blob: 03483d2a1acd91b225dcaa21774eac98c7c55d9d (
plain)
#[cfg(feature = "std")]
use std::error::Error;
use crate::{unexpected::Errorable, UnexpectedError};
mod sealed {
pub trait Sealed {}
impl<T, E> Sealed for Result<T, E> {}
}
use sealed::Sealed;
#[cfg(feature = "std")]
pub trait ResultErrorExt<T>: Sealed {
/// Converts `Result<T, E>` to `Result<T, UnexpectedError>`.
#[allow(clippy::missing_errors_doc)]
fn unexpect(self) -> Result<T, UnexpectedError>;
}
#[cfg(feature = "std")]
impl<T, E: Error + Send + Sync + 'static> ResultErrorExt<T> for Result<T, E> {
fn unexpect(self) -> Result<T, UnexpectedError> {
self.map_err(UnexpectedError::new)
}
}
pub trait ResultMsgExt<T>: Sealed {
/// Converts `Result<T, E>` to `Result<T, UnexpectedError>`.
///
/// This is provided for compatibility with `no_std`. If your type
/// implements [`Error`], then you should prefer that instead.
#[allow(clippy::missing_errors_doc)]
fn unexpect_msg(self) -> Result<T, UnexpectedError>;
}
impl<T, E: Errorable + 'static> ResultMsgExt<T> for Result<T, E> {
fn unexpect_msg(self) -> Result<T, UnexpectedError> {
self.map_err(UnexpectedError::msg)
}
}
|