Crates.io | future-result |
lib.rs | future-result |
version | 0.1.0 |
source | src |
created_at | 2020-08-08 07:01:35.529855 |
updated_at | 2020-08-08 09:48:02.353228 |
description | An ideomatic way of mapping a Result to a Future of Result |
homepage | |
repository | https://gitlab.com/IovoslavIovchev/future-result.git |
max_upload_size | |
id | 274255 |
size | 17,214 |
A Rust crate that provides an ideomatic way of mapping a Result
to a Future
of Result
.
use future_result::FutureResult;
async fn add_1(x: u32) -> u32 {
x + 1
}
fn main() {
let fut = async {
let ok: Result<u32, ()> = Ok(41);
let ok = ok.then_map(add_1).await;
assert_eq!(Ok(42), ok);
// ...
let err: Result<(), u32> = Err(9);
let err = err.then_map_err(add_1).await;
assert_eq!(Err(10), err);
};
futures::executor::block_on(fut);
}