diff options
| author | Botahamec <botahamec@outlook.com> | 2022-10-23 12:40:26 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2022-10-23 12:40:26 -0400 |
| commit | 7bc23b4865b39b9af900d7e2643ef1315793ba18 (patch) | |
| tree | b6b44af1811f1c71c0650e36f25b0e213bb3dcc9 /src/result.rs | |
| parent | 4147aa5450383d1dba9bc3739d56408fed8b0b58 (diff) | |
Added the result extensions
Diffstat (limited to 'src/result.rs')
| -rw-r--r-- | src/result.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/result.rs b/src/result.rs new file mode 100644 index 0000000..d5de01b --- /dev/null +++ b/src/result.rs @@ -0,0 +1,26 @@ +#[cfg(feature = "std")] +use std::error::Error; + +use crate::{unexpected::Errorable, UnexpectedError}; + +#[cfg(feature = "std")] +trait ResultErrorExt<T> { + 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) + } +} + +trait ResultMsgExt<T> { + 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) + } +} |
