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;
}
Required Associated Types§
Required Methods§
Sourcefn then_map<'async_trait, U, F, Fut>(
self,
f: F,
) -> Pin<Box<dyn Future<Output = Result<U, Self::Err>> + 'async_trait>>
fn then_map<'async_trait, U, F, Fut>( self, f: F, ) -> Pin<Box<dyn Future<Output = Result<U, Self::Err>> + '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);
});
Sourcefn then_map_err<'async_trait, U, F, Fut>(
self,
f: F,
) -> Pin<Box<dyn Future<Output = Result<Self::Ok, U>> + '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>>
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.