pub trait AsyncMapExt<T> {
// Required methods
fn async_map<TFn, TFuture>(self, f: TFn) -> AsyncMap<T, TFn, TFuture>
where TFn: FnOnce(T) -> TFuture,
TFuture: Future;
fn async_and_then<U, TFn, TFuture>(
self,
f: TFn,
) -> AsyncAndThen<T, TFn, TFuture>
where TFn: FnOnce(T) -> TFuture,
TFuture: Future<Output = Option<U>>;
}Required Methods§
Sourcefn async_map<TFn, TFuture>(self, f: TFn) -> AsyncMap<T, TFn, TFuture>
fn async_map<TFn, TFuture>(self, f: TFn) -> AsyncMap<T, TFn, TFuture>
Basically same as Option::map, but it accepts closure that returns Future
§Examples
use async_hofs::prelude::*;
assert_eq!(
Some(1).async_map(|x: i32| async move { x + 1 }).await,
Some(2),
);
assert_eq!(
None.async_map(|x: i32| async move { x + 1 }).await,
None
);Sourcefn async_and_then<U, TFn, TFuture>(
self,
f: TFn,
) -> AsyncAndThen<T, TFn, TFuture>
fn async_and_then<U, TFn, TFuture>( self, f: TFn, ) -> AsyncAndThen<T, TFn, TFuture>
Basically same as Option::and_then, but it accepts closure that returns Future
§Examples
use async_hofs::prelude::*;
assert_eq!(
Some(1)
.async_and_then(|x: i32| async move { Some(x + 1) })
.await,
Some(2),
);
assert_eq!(
Some(1)
.async_and_then(|x: i32| async move { Option::<i32>::None })
.await,
None
);
assert_eq!(
None.async_and_then(|x: i32| async move { Some(x + 1) })
.await,
None
);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.