#[derive(Debug, Clone)] struct Stu { name: String, age: u32, } impl Drop for Stu { fn drop(&mut self) { println!("Dropping CustomSmartPointer with data `{:?}`!", self); } } fn main() { let mut s = Stu { age: 11, name: String::from("ace"), }; println!("{:?}", s); s.age = 22; s.name = String::from("root"); println!("{:?}", s); let s2 = &s; println!("{:?} {:?}", s2, s); // 报错, 借用没被回收时, 不能改 // s.age = 33; // println!("{:?} {:?}", s2, s); let s3 = s.clone(); s.age = 33; println!("{:?} {:?}", s3, s); }