add is_ok to futures TryExtExt utils
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
1fdcab0319
commit
93130fbb85
1 changed files with 19 additions and 0 deletions
|
@ -10,6 +10,17 @@ pub trait TryExtExt<T, E>
|
||||||
where
|
where
|
||||||
Self: TryFuture<Ok = T, Error = E> + Send,
|
Self: TryFuture<Ok = T, Error = E> + 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<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
|
||||||
|
where
|
||||||
|
Self: Sized;
|
||||||
|
|
||||||
fn map_ok_or<U, F>(
|
fn map_ok_or<U, F>(
|
||||||
self, default: U, f: F,
|
self, default: U, f: F,
|
||||||
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> U, impl FnOnce(Self::Error) -> U>
|
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> U, impl FnOnce(Self::Error) -> U>
|
||||||
|
@ -32,6 +43,14 @@ impl<T, E, Fut> TryExtExt<T, E> for Fut
|
||||||
where
|
where
|
||||||
Fut: TryFuture<Ok = T, Error = E> + Send,
|
Fut: TryFuture<Ok = T, Error = E> + Send,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
|
fn is_ok(self) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
self.map_ok_or(false, |_| true)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn map_ok_or<U, F>(
|
fn map_ok_or<U, F>(
|
||||||
self, default: U, f: F,
|
self, default: U, f: F,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue