mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-24 21:32:15 +08:00
21 lines
451 B
Rust
Executable File
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
|