struct Foo; impl Drop for Foo { fn drop(&mut self) { println!("drop"); } } fn main() { let _ = Foo; println!("After"); }
http://is.gd/SQ6vcnspa
輸出是code
drop After
而若是咱們換成:blog
struct Foo; impl Drop for Foo { fn drop(&mut self) { println!("drop"); } } fn main() { let x = Foo; let _ = x; println!("After"); }
http://is.gd/uvJMO0class
After drop
雖然 eager drop 是很好的東西,可是,咱們其實不須要啊!im
咱們明明能夠顯式地給返回值調用一個 drop!di