Skip to content

Instantly share code, notes, and snippets.

Created August 3, 2015 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/7918bf9f83d079ac8960 to your computer and use it in GitHub Desktop.
Save anonymous/7918bf9f83d079ac8960 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
struct Yell { name: &'static str }
impl Drop for Yell {
fn drop(&mut self) {
println!("{} dropped!", self.name);
}
}
fn main() {
let bob = Yell { name: "Bob" };
let carol = Yell {
name: {
let carols_dad = Yell { name: "David" };
"Carol"
} //carols_dad out-of-scopes here
};
let ed = Yell { name: "Ed" };
let frank = Yell { name: panic!("Panic will destruct all objects reversly-ordered") };
println!("We never get to Gregor");
//never executes
let gregor = Yell { name: "Gregor" };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment