mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-25 05:42:18 +08:00
21 lines
451 B
Rust
21 lines
451 B
Rust
|
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
|