Skip to content

Instantly share code, notes, and snippets.

@silmeth
Last active February 7, 2017 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silmeth/f1d66c819862b418fd8862e3dc36875a to your computer and use it in GitHub Desktop.
Save silmeth/f1d66c819862b418fd8862e3dc36875a to your computer and use it in GitHub Desktop.
// In Rust Playground: https://is.gd/hyO195
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("Dropping!");
}
}
fn perform_drop(_: Foo) {}
fn main() {
println!("Start");
let x = Foo;
println!("x created, should drop now:");
perform_drop(x); // drop(x) *will* happen here
println!("After the drop, do some stuff…");
for i in (0..5).rev() {
println!("{}", i);
}
println!("main() returns here."); // if not for perform_drop(x), x would be dropped after that line
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment