diff --git a/src/core/utils/future/option_ext.rs b/src/core/utils/future/option_ext.rs index 920dd044..c7b65ef6 100644 --- a/src/core/utils/future/option_ext.rs +++ b/src/core/utils/future/option_ext.rs @@ -6,6 +6,14 @@ pub trait OptionExt { fn is_none_or(self, f: impl FnOnce(&T) -> bool + Send) -> impl Future + Send; fn is_some_and(self, f: impl FnOnce(&T) -> bool + Send) -> impl Future + Send; + + fn unwrap_or(self, t: T) -> impl Future + Send; + + fn unwrap_or_else(self, f: impl FnOnce() -> T + Send) -> impl Future + Send; + + fn unwrap_or_default(self) -> impl Future + Send + where + T: Default; } impl OptionExt for OptionFuture @@ -22,4 +30,20 @@ where fn is_some_and(self, f: impl FnOnce(&T) -> bool + Send) -> impl Future + Send { self.map(|o| o.as_ref().is_some_and(f)) } + + #[inline] + fn unwrap_or(self, t: T) -> impl Future + Send { self.map(|o| o.unwrap_or(t)) } + + #[inline] + fn unwrap_or_else(self, f: impl FnOnce() -> T + Send) -> impl Future + Send { + self.map(|o| o.unwrap_or_else(f)) + } + + #[inline] + fn unwrap_or_default(self) -> impl Future + Send + where + T: Default, + { + self.map(Option::unwrap_or_default) + } }