#[derive(Debug, Clone)]
pub enum AsyncResult<T, E> {
Async(T),
Sync(T),
Error(E),
}
impl<T, E> AsyncResult<T, E> {
#[must_use]
pub fn is_async(&self) -> bool {
matches!(self, AsyncResult::Async(_))
}
#[must_use]
pub fn is_sync(&self) -> bool {
matches!(self, AsyncResult::Sync(_))
}
#[must_use]
pub fn is_error(&self) -> bool {
matches!(self, AsyncResult::Error(_))
}
pub fn into_result(self) -> Result<T, E> {
match self {
AsyncResult::Async(v) | AsyncResult::Sync(v) => Ok(v),
AsyncResult::Error(e) => Err(e),
}
}
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> AsyncResult<U, E> {
match self {
AsyncResult::Async(v) => AsyncResult::Async(f(v)),
AsyncResult::Sync(v) => AsyncResult::Sync(f(v)),
AsyncResult::Error(e) => AsyncResult::Error(e),
}
}
}