Skip to content

Instantly share code, notes, and snippets.

@qezz
Forked from anonymous/playground.rs
Last active August 29, 2015 14:26
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 qezz/5ff432e5c9318dc259d0 to your computer and use it in GitHub Desktop.
Save qezz/5ff432e5c9318dc259d0 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") };
//never executes
println!("We never get to Gregor");
let gregor = Yell { name: "Gregor" };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment