#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unsafe_code)]
#![deny(missing_docs, broken_intra_doc_links)]
pub trait OptionExt {
type Item;
fn err_or<O>(self, ok: O) -> Result<O, Self::Item>;
fn err_or_else<O, F>(self, ok: F) -> Result<O, Self::Item>
where
F: FnOnce() -> O;
}
impl<T> OptionExt for Option<T> {
type Item = T;
#[inline]
fn err_or<O>(self, ok: O) -> Result<O, Self::Item> {
match self {
Some(v) => Err(v),
None => Ok(ok),
}
}
#[inline]
fn err_or_else<O, F>(self, ok: F) -> Result<O, Self::Item>
where
F: FnOnce() -> O,
{
match self {
Some(v) => Err(v),
None => Ok(ok()),
}
}
}