diff options
| author | Botahamec <botahamec@outlook.com> | 2023-08-08 18:41:14 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2023-08-08 18:41:14 -0400 |
| commit | 8a9d48d97cda01bb1d769d9d98c38cd50218d6c7 (patch) | |
| tree | eef8d30320e42f244ebc8c8e6cb400bb5381792c /src/result.rs | |
| parent | b9dfd2ceef09012a1917eab192b2a90a5372d349 (diff) | |
Allow conversion from Option to Result
Diffstat (limited to 'src/result.rs')
| -rw-r--r-- | src/result.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/result.rs b/src/result.rs index 7afceed..25392c8 100644 --- a/src/result.rs +++ b/src/result.rs @@ -6,6 +6,7 @@ use crate::{unexpected::Errorable, RawUnexpected}; mod sealed { pub trait Sealed {} impl<T, E> Sealed for Result<T, E> {} + impl<T> Sealed for Option<T> {} } use sealed::Sealed; @@ -71,6 +72,12 @@ impl<T> ResultErrorExt<T> for Result<T, RawUnexpected> { } } +impl<T> ResultErrorExt<T> for Option<T> { + fn unexpect(self) -> Result<T, RawUnexpected> { + self.ok_or_else(RawUnexpected::none) + } +} + /// Provides [`Result::unexpect_msg`] /// /// [`Result::unexpect_msg`]: `ResultMsgExt::unexpect_msg` |
