Trait FutureResult

Source
pub trait FutureResult {
    type Ok;
    type Err;

    // Required methods
    fn then_map<'async_trait, U, F, Fut>(
        self,
        f: F,
    ) -> Pin<Box<dyn Future<Output = Result<U, Self::Err>> + 'async_trait>>
       where F: FnOnce(Self::Ok) -> Fut + 'async_trait,
             Fut: Future<Output = U> + 'async_trait,
             U: 'async_trait,
             Self: 'async_trait;
    fn then_map_err<'async_trait, U, F, Fut>(
        self,
        f: F,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Ok, U>> + 'async_trait>>
       where F: FnOnce(Self::Err) -> Fut + 'async_trait,
             Fut: Future<Output = U> + 'async_trait,
             U: 'async_trait,
             Self: 'async_trait;
}
Expand description

A Result, which can be transformed into a Future of Result

Required Associated Types§

Source

type Ok

The success value of the Result

Source

type Err

The error value of the Result

Required Methods§

Source

fn then_map<'async_trait, U, F, Fut>( self, f: F, ) -> Pin<Box<dyn Future<Output = Result<U, Self::Err>> + 'async_trait>>
where F: FnOnce(Self::Ok) -> Fut + 'async_trait, Fut: Future<Output = U> + 'async_trait, U: 'async_trait, Self: 'async_trait,

Maps a Result<T, E> to a Future<Output = Result<U, E> by applying a function to the contained Ok value. Err is left untouched.

§Examples
let ok: Result<u8, ()> = Ok(1);
let err: Result<bool, ()> = Err(());

futures::executor::block_on(async move {
    let ok = ok.then_map(|x| async move { x + 6 }).await;
    assert_eq!(Ok(7), ok);

    let err = err.then_map(|b| async move { !b }).await;
    assert_eq!(Err(()), err);
});
Source

fn then_map_err<'async_trait, U, F, Fut>( self, f: F, ) -> Pin<Box<dyn Future<Output = Result<Self::Ok, U>> + 'async_trait>>
where F: FnOnce(Self::Err) -> Fut + 'async_trait, Fut: Future<Output = U> + 'async_trait, U: 'async_trait, Self: 'async_trait,

Maps a Result<T, E> to a Future<Output = Result<T, U> by applying a function to the contained Err value. Ok is left untouched.

§Examples
let ok: Result<(), bool> = Ok(());
let err: Result<(), u8> = Err(8);

futures::executor::block_on(async move {
    let err = err.then_map_err(|x| async move { x - 3 }).await;
    assert_eq!(Err(5), err);

    let ok = ok.then_map_err(|b| async move { !b }).await;
    assert_eq!(Ok(()), ok);
});

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: Sync, E: Sync> FutureResult for Result<T, E>

Source§

type Ok = T

Source§

type Err = E

Source§

fn then_map<'async_trait, U, F, Fut>( self, f: F, ) -> Pin<Box<dyn Future<Output = Result<U, E>> + 'async_trait>>
where Self: Sized + 'async_trait, F: FnOnce(T) -> Fut + 'async_trait, Fut: Future<Output = U> + 'async_trait, U: 'async_trait,

Source§

fn then_map_err<'async_trait, U, F, Fut>( self, f: F, ) -> Pin<Box<dyn Future<Output = Result<T, U>> + 'async_trait>>
where Self: Sized + 'async_trait, F: FnOnce(E) -> Fut + 'async_trait, Fut: Future<Output = U> + 'async_trait, U: 'async_trait,

Implementors§