use alloc::{
collections::{BTreeMap, BTreeSet},
string::String,
vec::Vec,
};
use crate::path::FsPath;
#[derive(Debug)]
pub enum MaildirCoroutineState<Y, R> {
Yielded(Y),
Complete(R),
}
pub trait MaildirCoroutine {
type Yield;
type Return;
fn resume(
&mut self,
arg: Option<MaildirReply>,
) -> MaildirCoroutineState<Self::Yield, Self::Return>;
}
#[derive(Debug)]
pub enum MaildirYield {
WantsFileExists(BTreeSet<FsPath>),
WantsDirExists(BTreeSet<FsPath>),
WantsDirRead(BTreeSet<FsPath>),
WantsFileRead(BTreeSet<FsPath>),
WantsFileCreate(BTreeMap<FsPath, Vec<u8>>),
WantsDirCreate(BTreeSet<FsPath>),
WantsDirRemove(BTreeSet<FsPath>),
WantsRename(Vec<(FsPath, FsPath)>),
WantsCopy(Vec<(FsPath, FsPath)>),
WantsTime,
WantsPid,
WantsHostname,
}
#[derive(Clone, Debug)]
pub enum MaildirReply {
FileExists(BTreeMap<FsPath, bool>),
DirExists(BTreeMap<FsPath, bool>),
DirRead(BTreeMap<FsPath, BTreeSet<FsPath>>),
FileRead(BTreeMap<FsPath, Vec<u8>>),
FileCreate,
DirCreate,
DirRemove,
Rename,
Copy,
Time { secs: u64, nanos: u32 },
Pid(u32),
Hostname(String),
}
#[macro_export]
macro_rules! maildir_try {
($coroutine:expr, $arg:expr $(,)?) => {
match $crate::coroutine::MaildirCoroutine::resume($coroutine, $arg) {
$crate::coroutine::MaildirCoroutineState::Yielded(y) => {
return $crate::coroutine::MaildirCoroutineState::Yielded(y.into());
}
$crate::coroutine::MaildirCoroutineState::Complete(Err(err)) => {
return $crate::coroutine::MaildirCoroutineState::Complete(Err(err.into()));
}
$crate::coroutine::MaildirCoroutineState::Complete(Ok(value)) => value,
}
};
}