Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate tokio;
- extern crate futures;
- use tokio::io;
- use tokio::net::TcpStream;
- use tokio::prelude::*;
- use tokio::net::tcp::ConnectFuture;
- //use futures;
- use futures::future::Future;
- use core::prelude::v1::Option;
- //use core::intrinsics;
- //use futures::future::map;
- #[derive(Debug)]
- pub struct MyFuture {
- }
- pub struct Map< A,F,U> where A: tFuture,F:FnMut(u32)-> U
- {
- future: A,
- f1: Option<F>,
- }
- pub trait tFuture {
- type Item;
- fn map<F, U>(self, mut f: F) -> Map<Self, F,U>
- where F: FnMut(u32) -> U,
- Self: Sized,
- {
- f(1);
- Map {
- future:self,
- f1: Some(f),
- }
- }
- fn run(self)
- where Self: Sized
- {
- }
- }
- impl<A:tFuture,F,U> tFuture for Map<A,F,U>
- where F: FnMut(u32) -> U,
- Self: Sized,
- {
- type Item=();
- fn run(self)
- {
- let mut f = self.f1.unwrap();
- f(2);
- }
- }
- impl tFuture for MyFuture {
- type Item = String;
- }
- pub fn myrun<F>(future: F)
- where F: tFuture<Item=()> + 'static,
- {
- future.run();
- }
- fn test001<F>(f:F) ->Option<F>
- {
- let t = Some(f);
- return t;
- }
- fn main() {
- let expensive_closure = |num:u32| {
- dbg!(num);
- };
- let t = test001(expensive_closure);
- expensive_closure(2);
- let t2= t.unwrap();
- t2(3);
- let test =MyFuture{};
- myrun(test.map(|x:u32|{
- dbg!(x)
- })
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement