fn main() {↵
let s1 = String::from("hello");↵
let s2 = s1.clone();↵
println!("s1: {}, s2: {}", s1, s2);↵
↵
let s3 = String::from("world");↵
let s4 = take_ownership(s3);↵
println!("s4: {}", s4);↵
↵
let s5 = String::from("rust");↵
let len = borrow_string(&s5);↵
println!("s5: {}, len: {}", s5, len);↵
↵
let mut s6 = String::from("hello");↵
modify_string(&mut s6);↵
println!("Modified: {}", s6);↵
}↵
↵
fn take_ownership(s: String) -> String {↵
s↵
}↵
↵
fn borrow_string(s: &String) -> usize {↵
s.len()↵
}↵
↵
fn modify_string(s: &mut String) {↵
s.push_str(" world");↵
}