pub trait AsyncMapExt<T, E> {
// Required methods
fn async_map<TFn, TFuture>(self, f: TFn) -> AsyncMap<T, E, TFn, TFuture>
where TFn: FnOnce(T) -> TFuture,
TFuture: Future;
fn async_and_then<U, TFn, TFuture>(
self,
f: TFn,
) -> AsyncAndThen<T, E, TFn, TFuture>
where TFn: FnOnce(T) -> TFuture,
TFuture: Future<Output = Result<U, E>>;
}Required Methods§
Sourcefn async_map<TFn, TFuture>(self, f: TFn) -> AsyncMap<T, E, TFn, TFuture>
fn async_map<TFn, TFuture>(self, f: TFn) -> AsyncMap<T, E, TFn, TFuture>
Basically same as Result::map, but it accepts closure that returns Future
§Examples
use async_hofs::prelude::*;
type Result = core::result::Result<i32, i32>;
assert_eq!(
Result::Ok(1).async_map(|x: i32| async move { x + 1 }).await,
Result::Ok(2),
);
assert_eq!(
Result::Err(4).async_map(|x: i32| async move { x + 1 }).await,
Result::Err(4),
);Sourcefn async_and_then<U, TFn, TFuture>(
self,
f: TFn,
) -> AsyncAndThen<T, E, TFn, TFuture>
fn async_and_then<U, TFn, TFuture>( self, f: TFn, ) -> AsyncAndThen<T, E, TFn, TFuture>
Basically same as Result::and_then, but it accepts closure that returns Future
§Examples
use async_hofs::prelude::*;
type Result = core::result::Result<i32, i32>;
assert_eq!(
Result::Ok(1)
.async_and_then(|x: i32| async move { Ok(x + 1) })
.await,
Result::Ok(2),
);
assert_eq!(
Result::Ok(1)
.async_and_then(|x: i32| async move { Err(x + 1) })
.await,
Result::Err(2),
);
assert_eq!(
Result::Err(4)
.async_and_then(|x: i32| async move { Ok(x + 1) })
.await,
Result::Err(4),
);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.