Last active
February 7, 2017 10:19
-
-
Save silmeth/f1d66c819862b418fd8862e3dc36875a to your computer and use it in GitHub Desktop.
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
// 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