SHARE
TWEET

Untitled

a guest Oct 13th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern crate tokio;
  2. extern crate futures;
  3. use tokio::io;
  4. use tokio::net::TcpStream;
  5. use tokio::prelude::*;
  6. use tokio::net::tcp::ConnectFuture;
  7.  
  8. //use futures;
  9. use futures::future::Future;
  10. use core::prelude::v1::Option;
  11. //use core::intrinsics;
  12. //use futures::future::map;
  13. #[derive(Debug)]
  14. pub struct MyFuture {
  15. }
  16. pub struct Map< A,F,U> where A: tFuture,F:FnMut(u32)-> U
  17. {  
  18.     future: A,
  19.     f1: Option<F>,
  20. }
  21.  
  22. pub trait tFuture {
  23.     type Item;
  24.     fn map<F, U>(self, mut f: F) -> Map<Self, F,U>
  25.     where F: FnMut(u32) -> U,
  26.               Self: Sized,
  27.     {
  28.        f(1);
  29.         Map {
  30.             future:self,
  31.             f1: Some(f),
  32.         }
  33.     }
  34.     fn run(self)
  35.     where Self: Sized
  36.     {
  37.  
  38.     }
  39. }
  40.  
  41. impl<A:tFuture,F,U> tFuture for Map<A,F,U>
  42.     where F: FnMut(u32) -> U,
  43.               Self: Sized,
  44. {
  45.     type Item=();
  46.     fn run(self)
  47.     {
  48.         let mut f = self.f1.unwrap();
  49.         f(2);
  50.     }
  51. }
  52. impl tFuture for MyFuture {
  53.     type Item = String;
  54.    
  55. }
  56. pub fn myrun<F>(future: F)
  57. where F: tFuture<Item=()> + 'static,
  58. {
  59.     future.run();
  60. }
  61.  
  62. fn test001<F>(f:F) ->Option<F>
  63. {
  64.     let t = Some(f);
  65.     return t;
  66. }
  67. fn main() {
  68.     let expensive_closure = |num:u32| {
  69.         dbg!(num);
  70.     };
  71.     let t = test001(expensive_closure);
  72.     expensive_closure(2);
  73.     let t2= t.unwrap();
  74.     t2(3);
  75.     let test =MyFuture{};
  76.     myrun(test.map(|x:u32|{
  77.         dbg!(x)
  78.     })
  79.     );
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top