Created
November 20, 2015 05:52
-
-
Save anonymous/aa96e9e0fe78a09af2eb to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(fnbox)] | |
use std::boxed::FnBox; | |
struct Foo; | |
impl Foo { | |
pub fn new() -> Foo { | |
println!("foo: new"); | |
Foo | |
} | |
pub fn dowork(&self) { | |
println!("foo: doing work"); | |
} | |
} | |
impl Drop for Foo { | |
fn drop(&mut self) { | |
println!("foo: drop"); | |
} | |
} | |
fn process(foo: Foo) -> Box<FnBox()> { | |
Box::new(move || { | |
foo.dowork(); | |
/* info: foo is never dropped | |
* at the end of this closure despite | |
* being owned by the closure, this | |
* requires the caller to explicitly | |
* drop() captured members. | |
*/ | |
// uncomment | |
// drop(foo); // explicit drop!! | |
}) | |
} | |
fn main() { | |
let f = process(Foo::new()); | |
f(); | |
println!("main: exit"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment