#[cfg(any(feature = "alloc", feature = "std"))]
use alloc::string::String;
use crate::Error;
pub trait ResultExt<T, E>: Sized {
fn annotate(self, msg: &'static str) -> Result<T, Error<E>>;
#[cfg(any(feature = "alloc", feature = "std"))]
fn annotate_with<F>(self, f: F) -> Result<T, Error<E>>
where
F: FnOnce() -> String;
}
impl<T, E> ResultExt<T, E> for Result<T, E> {
#[inline]
fn annotate(self, msg: &'static str) -> Result<T, Error<E>> {
match self {
Ok(v) => Ok(v),
Err(e) => Err(Error::new(msg, e)),
}
}
#[cfg(any(feature = "alloc", feature = "std"))]
#[inline]
fn annotate_with<F>(self, f: F) -> Result<T, Error<E>>
where
F: FnOnce() -> String,
{
match self {
Ok(v) => Ok(v),
Err(e) => Err(Error::new_owned(f(), e)),
}
}
}