Created
December 14, 2022 16:12
-
-
Save MOZGIII/92fe0bb3ced4bc7522cb4cf5b055bb72 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A step in a process. | |
pub trait Step<Context> { | |
/// The next step in the process. | |
type NextStep: Step<Context>; | |
/// The error. | |
type Error; | |
/// A function to allow the step to progress. | |
fn progress(self, context: Context) -> Result<Self::NextStep, Self::Error>; | |
} | |
/// The terminal step. | |
pub enum Terminal {} | |
impl<Context> Step<Context> for Terminal { | |
type NextStep = Terminal; | |
type Error = std::convert::Infallible; | |
fn progress(self, _context: Context) -> Result<Self::NextStep, Self::Error> { | |
// This paritcular call can never be reached since it takes self by value but that's | |
// a `Terminal` which is an unconstructable type. | |
unreachable!() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment