Updated 'src/smart_pointers/deref-t'.

This commit is contained in:
Hector PENG
2026-04-03 14:30:42 +08:00
parent 6ee46dc93a
commit faeed0ebad
3 changed files with 41 additions and 38 deletions

View File

@@ -17,9 +17,12 @@ impl<T> Deref for MyBox<T> {
}
fn main() {
let x = 5;
let y = MyBox::new(x);
hello("Rust");
assert_eq! (5, x);
assert_eq! (5, *y);
let m = MyBox::new(String::from("Rust"));
hello(&m);
}
fn hello(name: &str) {
println! ("你好,{name}");
}