use core::fmt::Debug;
pub mod prelude {
#[doc(inline)]
pub use super::{ok, unwrap};
}
pub trait Unwrap {
type Value;
fn unwrap(self) -> Self::Value;
}
pub trait Ok {
type Value;
fn ok(self) -> Option<Self::Value>;
}
pub fn ok<R: Ok>(result: R) -> Option<R::Value> {
result.ok()
}
pub fn unwrap<U: Unwrap>(unwrappable: U) -> U::Value {
unwrappable.unwrap()
}
impl<T> Unwrap for Option<T> {
type Value = T;
fn unwrap(self) -> Self::Value {
Option::unwrap(self)
}
}
impl<T, E: Debug> Unwrap for Result<T, E> {
type Value = T;
fn unwrap(self) -> Self::Value {
Result::unwrap(self)
}
}
impl<T> Ok for Option<T> {
type Value = T;
fn ok(self) -> Self {
self
}
}
impl<T, E> Ok for Result<T, E> {
type Value = T;
fn ok(self) -> Option<T> {
self.ok()
}
}