fn main() { let s1 = String::from("hello"); // s1 is moved to s2. s1 is no longer valid. let s2 = s2_owner(s1); // s2 is moved to s3. s2 is no longer valid. let s3 = s2; // s3 is valid here println!("s3: {}", s3); // This would cause a compile-time error: borrow of moved value: `s1` // println!("s1: {}", s1); // This would cause a compile-time error: borrow of moved value: `s2` // println!("s2: {}", s2); } // s: String takes ownership of the passed string. // It then returns a new String, transferring ownership of the new string back. fn s2_owner(s: String) -> String { println!("Inside s2_owner: {}", s); String::from("world") }