Guest User

Untitled

a guest
Jun 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. extern crate futures;
  2. extern crate tokio_threadpool;
  3.  
  4. use futures::future::{ok, err};
  5. use futures::future::Either;
  6. use futures::Future;
  7. use futures::FutureExt;
  8.  
  9. fn a() -> impl Future<Item = Result<i32, u64>, Error = String> {
  10. ok(Ok(5))
  11. }
  12.  
  13. fn do_it(
  14. a: impl Future<Item = Result<i32, u64>, Error = String>,
  15. ) -> impl Future<Item = i32, Error = Either<u64, String>> {
  16. a.and_then(|res| {
  17. res.map(|a| ok(a))
  18. .unwrap_or_else(|b| err(Either::Left(b)))
  19. }).map_err(|c| Either::Right(c))
  20.  
  21. //a.then(|res| match res {
  22. // Ok(Ok(a)) => Ok(a),
  23. // Ok(Err(b)) => Err(Either::Left(b)),
  24. // Err(c) => Err(Either::Right(c))
  25. //})
  26. }
  27.  
  28. fn main() {}
Add Comment
Please, Sign In to add comment