add unwrap_or to TryFutureExtExt
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
4485f36e34
commit
dd9f53080a
1 changed files with 16 additions and 1 deletions
|
@ -1,6 +1,9 @@
|
|||
//! Extended external extensions to futures::TryFutureExt
|
||||
|
||||
use futures::{future::MapOkOrElse, TryFuture, TryFutureExt};
|
||||
use futures::{
|
||||
future::{MapOkOrElse, UnwrapOrElse},
|
||||
TryFuture, TryFutureExt,
|
||||
};
|
||||
|
||||
/// This interface is not necessarily complete; feel free to add as-needed.
|
||||
pub trait TryExtExt<T, E>
|
||||
|
@ -19,6 +22,10 @@ where
|
|||
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> Option<Self::Ok>, impl FnOnce(Self::Error) -> Option<Self::Ok>>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
fn unwrap_or(self, default: Self::Ok) -> UnwrapOrElse<Self, impl FnOnce(Self::Error) -> Self::Ok>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
impl<T, E, Fut> TryExtExt<T, E> for Fut
|
||||
|
@ -45,4 +52,12 @@ where
|
|||
{
|
||||
self.map_ok_or(None, Some)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn unwrap_or(self, default: Self::Ok) -> UnwrapOrElse<Self, impl FnOnce(Self::Error) -> Self::Ok>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.unwrap_or_else(move |_| default)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue