pub trait AsyncMapExt<T>: Sized {
// Required method
fn async_map<TFn, TFuture, U>(self, f: TFn) -> AsyncMap<Self, TFn, TFuture>
where TFn: FnMut(T) -> TFuture,
TFuture: Future<Output = U>;
}Required Methods§
Sourcefn async_map<TFn, TFuture, U>(self, f: TFn) -> AsyncMap<Self, TFn, TFuture>
fn async_map<TFn, TFuture, U>(self, f: TFn) -> AsyncMap<Self, TFn, TFuture>
Basically same as Iterator::map, but it accepts closure that returns
Future and creates new Stream instead of Iterator.
§Examples
use async_hofs::prelude::*;
use tokio_stream::StreamExt; // for .collect
assert_eq!(
vec![1, 2]
.into_iter()
.async_map(|x| async move { x + 1 })
.collect::<Vec<_>>()
.await,
vec![2, 3],
);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.