Updated 'src/smart_pointers/drop-t'.

This commit is contained in:
Hector PENG
2026-04-03 18:50:08 +08:00
parent 07caa30b15
commit 2062138bd3
5 changed files with 101 additions and 107 deletions

View File

@@ -0,0 +1,6 @@
[package]
name = "drop-example"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@@ -0,0 +1,18 @@
struct CustomSmartPointer {
data: String,
}
impl Drop for CustomSmartPointer {
fn drop(&mut self) {
println! ("正在以数据 `{}` 弃用 CustomSmartPointer", self.data);
}
}
fn main() {
let c = CustomSmartPointer {
data: String::from("我的事情"),
};
println! ("CustomSmartPointer 实例已创建");
drop(c);
println! ("CustomSmartPointer 在 main 结束前被弃用");
}

View File

@@ -1,8 +0,0 @@
[package]
name = "drop_func_demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@@ -1,19 +0,0 @@
struct CustomSmartPointer {
data: String,
}
impl Drop for CustomSmartPointer {
fn drop(&mut self) {
println! ("正在使用数据 `{}` 弃用 CustomSmartPointer", self.data);
}
}
fn main() {
let c = CustomSmartPointer {
data: String::from("我的事情"),
};
println! ("已创建出一个 CustomSmartPointer 实例。");
drop(c);
println! ("在 main 结束之前这个 CustomSmartPointer 已被弃用。")
}