trpl-zh-cn/listings/ch15-smart-pointers/listing-15-16/src/main.rs
2022-02-06 16:43:51 +08:00

21 lines
451 B
Rust
Executable File

struct CustomSmartPointer {
data: String,
}
impl Drop for CustomSmartPointer {
fn drop(&mut self) {
println!("Dropping CustomSmartPointer with data `{}`!", self.data);
}
}
// ANCHOR: here
fn main() {
let c = CustomSmartPointer {
data: String::from("some data"),
};
println!("CustomSmartPointer created.");
drop(c);
println!("CustomSmartPointer dropped before the end of main.");
}
// ANCHOR_END: here