Skip to content

Instantly share code, notes, and snippets.

@siburu
Last active March 28, 2019 05:12
Show Gist options
  • Save siburu/6e4db443fdcad98a296c6758455f7942 to your computer and use it in GitHub Desktop.
Save siburu/6e4db443fdcad98a296c6758455f7942 to your computer and use it in GitHub Desktop.
struct Hoge {
agony: String
}
impl Drop for Hoge {
fn drop(&mut self) {
println!("drop: {}", self.agony);
}
}
fn main() {
let mut h = Hoge { agony: String::from("bye bye") };
// shadow1: Hoge => &mut Hoge::agony
let h = &mut h.agony;
println!("after shadow1: {}", h);
*h = String::from("hello hello");
// shadow 2: &mut Hoge::agony => integer
let h = 123;
println!("after shadow2: {}", h);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment