-
-
Save qezz/5ff432e5c9318dc259d0 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
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