From 93130fbb85e4f5645d1b98aeddd8e1828b1b936c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 21 Oct 2024 20:21:00 +0000 Subject: [PATCH] add is_ok to futures TryExtExt utils Signed-off-by: Jason Volk --- src/core/utils/future/try_ext_ext.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/core/utils/future/try_ext_ext.rs b/src/core/utils/future/try_ext_ext.rs index d30d2cac..7c0b36a2 100644 --- a/src/core/utils/future/try_ext_ext.rs +++ b/src/core/utils/future/try_ext_ext.rs @@ -10,6 +10,17 @@ pub trait TryExtExt where Self: TryFuture + Send, { + /// Resolves to a bool for whether the TryFuture (Future of a Result) + /// resolved to Ok or Err. + /// + /// is_ok() has to consume *self rather than borrow. The intent of this + /// extension is therefor for a caller only ever caring about result status + /// while discarding all contents. + #[allow(clippy::wrong_self_convention)] + fn is_ok(self) -> MapOkOrElse bool, impl FnOnce(Self::Error) -> bool> + where + Self: Sized; + fn map_ok_or( self, default: U, f: F, ) -> MapOkOrElse U, impl FnOnce(Self::Error) -> U> @@ -32,6 +43,14 @@ impl TryExtExt for Fut where Fut: TryFuture + Send, { + #[inline] + fn is_ok(self) -> MapOkOrElse bool, impl FnOnce(Self::Error) -> bool> + where + Self: Sized, + { + self.map_ok_or(false, |_| true) + } + #[inline] fn map_ok_or( self, default: U, f: F,