AsyncMapExt

Trait AsyncMapExt 

Source
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§

Source

fn async_map<TFn, TFuture, U>(self, f: TFn) -> AsyncMap<Self, TFn, TFuture>
where TFn: FnMut(T) -> TFuture, TFuture: Future<Output = U>,

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.

Implementors§

Source§

impl<TIter, T> AsyncMapExt<T> for TIter
where TIter: Iterator<Item = T>,