#[cfg(feature = "std")] use std::error::Error; use crate::{unexpected::Errorable, UnexpectedError}; mod sealed { pub trait Sealed {} impl Sealed for Result {} } use sealed::Sealed; #[cfg(feature = "std")] pub trait ResultErrorExt: Sealed { /// Converts `Result` to `Result`. #[allow(clippy::missing_errors_doc)] fn unexpect(self) -> Result; } #[cfg(feature = "std")] impl ResultErrorExt for Result { fn unexpect(self) -> Result { self.map_err(UnexpectedError::new) } } pub trait ResultMsgExt: Sealed { /// Converts `Result` to `Result`. /// /// 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; } impl ResultMsgExt for Result { fn unexpect_msg(self) -> Result { self.map_err(UnexpectedError::msg) } }