Skip to content

Instantly share code, notes, and snippets.

@MOZGIII
Created December 14, 2022 16:12
Show Gist options
  • Save MOZGIII/92fe0bb3ced4bc7522cb4cf5b055bb72 to your computer and use it in GitHub Desktop.
Save MOZGIII/92fe0bb3ced4bc7522cb4cf5b055bb72 to your computer and use it in GitHub Desktop.
/// 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