Guest User

Untitled

a guest
Nov 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. extern crate futures;
  2. extern crate tokio;
  3.  
  4. mod hw {
  5. pub use futures::{Async, Future, Poll, try_ready};
  6. pub use std::fmt;
  7.  
  8. pub struct HelloWorld;
  9. impl Future for HelloWorld {
  10. type Item = String;
  11. type Error = ();
  12.  
  13. fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
  14. Ok(Async::Ready("helloworld".to_string()))
  15. }
  16. }
  17.  
  18. pub struct Display<T>(pub T);
  19. impl<T> Future for Display<T>
  20. where
  21. T: Future,
  22. T::Item: fmt::Display,
  23. {
  24. type Item = ();
  25. type Error = T::Error;
  26.  
  27. fn poll(&mut self) -> Poll<(), T::Error> {
  28. let value = try_ready!(self.0.poll());
  29. println!("{}", value);
  30. Ok(Async::Ready(()))
  31. }
  32. }
  33. }
  34.  
  35. use hw::{Display, HelloWorld};
  36.  
  37. fn main() {
  38. let future = Display(HelloWorld);
  39. tokio::run(future);
  40. }
Add Comment
Please, Sign In to add comment