Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate futures;
- extern crate tokio_threadpool;
- use futures::future::{ok, err};
- use futures::future::Either;
- use futures::Future;
- use futures::FutureExt;
- fn a() -> impl Future<Item = Result<i32, u64>, Error = String> {
- ok(Ok(5))
- }
- fn do_it(
- a: impl Future<Item = Result<i32, u64>, Error = String>,
- ) -> impl Future<Item = i32, Error = Either<u64, String>> {
- a.and_then(|res| {
- res.map(|a| ok(a))
- .unwrap_or_else(|b| err(Either::Left(b)))
- }).map_err(|c| Either::Right(c))
- //a.then(|res| match res {
- // Ok(Ok(a)) => Ok(a),
- // Ok(Err(b)) => Err(Either::Left(b)),
- // Err(c) => Err(Either::Right(c))
- //})
- }
- fn main() {}
Add Comment
Please, Sign In to add comment