The Drop
Trait
Drop
ํธ๋ ์ดํธ๋ ๊ฐ์ด ์ค์ฝํ ๋ฐ์ผ๋ก ๋๊ฐ๋ ์คํํ๋ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์ต๋๋ค:
Values which implement
Drop
can specify code to run when they go out of scope:
struct Droppable { name: &'static str, } impl Drop for Droppable { fn drop(&mut self) { println!("Dropping {}", self.name); } } fn main() { let a = Droppable { name: "a" }; { let b = Droppable { name: "b" }; { let c = Droppable { name: "c" }; let d = Droppable { name: "d" }; println!("Exiting block B"); } println!("Exiting block A"); } drop(a); println!("Exiting main"); }