use std::pin::Pin;
pub trait Coroutine {
type Yield;
type Resume;
type Return;
fn resume_with(
self: Pin<&mut Self>,
arg: Self::Resume,
) -> GeneratorState<Self::Yield, Self::Return>;
}
pub trait Generator {
type Yield;
type Return;
fn resume(self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return>;
}
impl<C: Coroutine<Resume = ()>> Generator for C {
type Yield = <Self as Coroutine>::Yield;
type Return = <Self as Coroutine>::Return;
#[must_use]
fn resume(self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
self.resume_with(())
}
}
#[derive(PartialEq, Debug)]
#[allow(clippy::module_name_repetitions)]
pub enum GeneratorState<Y, R> {
Yielded(Y),
Complete(R),
}