use alloc::vec::Vec;
#[derive(Debug)]
pub enum SmtpCoroutineState<Y, R> {
Yielded(Y),
Complete(R),
}
pub trait SmtpCoroutine {
type Yield;
type Return;
fn resume(&mut self, arg: Option<&[u8]>) -> SmtpCoroutineState<Self::Yield, Self::Return>;
}
#[derive(Debug)]
pub enum SmtpYield {
WantsRead,
WantsWrite(Vec<u8>),
}
#[macro_export]
macro_rules! smtp_try {
($coroutine:expr, $arg:expr $(,)?) => {
match $crate::coroutine::SmtpCoroutine::resume($coroutine, $arg) {
$crate::coroutine::SmtpCoroutineState::Yielded(y) => {
return $crate::coroutine::SmtpCoroutineState::Yielded(y.into());
}
$crate::coroutine::SmtpCoroutineState::Complete(Err(err)) => {
return $crate::coroutine::SmtpCoroutineState::Complete(Err(err.into()));
}
$crate::coroutine::SmtpCoroutineState::Complete(Ok(value)) => value,
}
};
}