use core::fmt::Display;
use crate::Error;
#[cfg_attr(
any(feature = "rust-v1.81", feature = "std"),
doc = r##"
[`prelude::Stashable`]: crate::prelude::Stashable
"##
)]
#[cfg_attr(
not(any(feature = "rust-v1.81", feature = "std")),
doc = r##"
[`prelude::Stashable`]: crate::surrogate_error_trait::prelude::Stashable
"##
)]
pub trait OrWrapWith<F, M, T, E>
where
F: FnOnce() -> M,
M: Display,
{
fn or_wrap_with<I>(self, f: F) -> Result<T, Error<I>>
where
E: Into<I>;
}
impl<F, M, T, E> OrWrapWith<F, M, T, E> for Result<T, E>
where
F: FnOnce() -> M,
M: Display,
{
#[track_caller]
fn or_wrap_with<I>(self, f: F) -> Result<T, Error<I>>
where
E: Into<I>,
{
match self {
Ok(t) => Ok(t),
Err(inner) => Err(Error::wrap_with(inner, f())),
}
}
}