From 8a9d48d97cda01bb1d769d9d98c38cd50218d6c7 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Tue, 8 Aug 2023 18:41:14 -0400 Subject: Allow conversion from Option to Result --- src/result.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/result.rs') 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 Sealed for Result {} + impl Sealed for Option {} } use sealed::Sealed; @@ -71,6 +72,12 @@ impl ResultErrorExt for Result { } } +impl ResultErrorExt for Option { + fn unexpect(self) -> Result { + self.ok_or_else(RawUnexpected::none) + } +} + /// Provides [`Result::unexpect_msg`] /// /// [`Result::unexpect_msg`]: `ResultMsgExt::unexpect_msg` -- cgit v1.2.3