Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct GE {
- env: Option<Box<Fn() -> i32>>,
- }
- struct HasDrop { i: i32 }
- impl Drop for HasDrop {
- fn drop(&mut self) {
- println!("Dropping!");
- }
- }
- impl GE {
- fn add<T>(&mut self, func: T) where T: 'static + Fn() -> i32 {
- self.env = Some(Box::new(func));
- }
- }
- fn o() {
- let mut g = GE { env: None };
- let fo = HasDrop { i: 20 };
- g.add(move || { fo.i });
- }
- fn main() {
- println!("A");
- o();
- println!("B");
- o();
- println!("C");
- o();
- println!("D");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement