AsyncMapExt

Trait AsyncMapExt 

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

Source

fn async_map<TFn, TFuture>(self, f: TFn) -> AsyncMap<T, E, TFn, TFuture>
where TFn: FnOnce(T) -> TFuture, TFuture: Future,

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),
);
Source

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>>,

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.

Implementations on Foreign Types§

Source§

impl<T, E> AsyncMapExt<T, E> for Result<T, E>

Source§

fn async_map<TFn, TFuture>(self, f: TFn) -> AsyncMap<T, E, TFn, TFuture>
where TFn: FnOnce(T) -> TFuture, TFuture: Future,

Source§

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>>,

Implementors§