use std::fmt::Debug;
pub enum Restion<T, E> {
Ok(T),
Err(E),
None,
}
impl<T, E> Restion<T, E> {
pub const fn is_ok(&self) -> bool {
matches!(self, Restion::Ok(_))
}
pub const fn is_err(&self) -> bool {
matches!(self, Restion::Err(_))
}
pub const fn is_none(&self) -> bool {
matches!(self, Restion::None)
}
}
impl<T, E: Debug> Restion<T, E> {
pub fn unwrap(self) -> T {
match self {
Restion::Ok(t) => t,
Restion::Err(e) => panic!("{:?}", e),
Restion::None => panic!("called `Restion::unwrap()` on a `None` value"),
}
}
}
impl<T, E> From<Result<T, E>> for Restion<T, E> {
fn from(result: Result<T, E>) -> Self {
match result {
Ok(t) => Restion::Ok(t),
Err(e) => Restion::Err(e),
}
}
}
impl<T> From<Option<T>> for Restion<T, ()> {
fn from(option: Option<T>) -> Self {
match option {
Some(t) => Restion::Ok(t),
None => Restion::None,
}
}
}