SHARE
TWEET

Untitled

a guest May 20th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct GE {
  2.     env: Option<Box<Fn() -> i32>>,
  3. }
  4.  
  5. struct HasDrop { i: i32 }
  6.  
  7. impl Drop for HasDrop {
  8.     fn drop(&mut self) {
  9.         println!("Dropping!");
  10.     }
  11. }
  12.  
  13. impl GE {
  14.     fn add<T>(&mut self, func: T) where T: 'static + Fn() -> i32 {
  15.          self.env = Some(Box::new(func));
  16.     }
  17. }
  18.  
  19. fn o() {
  20.     let mut g = GE { env: None };
  21.     let fo = HasDrop { i: 20 };
  22.     g.add(move || { fo.i });
  23. }
  24.  
  25. fn main() {
  26.     println!("A");
  27.     o();
  28.     println!("B");
  29.     o();
  30.     println!("C");
  31.     o();
  32.     println!("D");
  33. }
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