Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate futures;
- extern crate tokio;
- mod hw {
- pub use futures::{Async, Future, Poll, try_ready};
- pub use std::fmt;
- pub struct HelloWorld;
- impl Future for HelloWorld {
- type Item = String;
- type Error = ();
- fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
- Ok(Async::Ready("helloworld".to_string()))
- }
- }
- pub struct Display<T>(pub T);
- impl<T> Future for Display<T>
- where
- T: Future,
- T::Item: fmt::Display,
- {
- type Item = ();
- type Error = T::Error;
- fn poll(&mut self) -> Poll<(), T::Error> {
- let value = try_ready!(self.0.poll());
- println!("{}", value);
- Ok(Async::Ready(()))
- }
- }
- }
- use hw::{Display, HelloWorld};
- fn main() {
- let future = Display(HelloWorld);
- tokio::run(future);
- }
Add Comment
Please, Sign In to add comment