这个有意思,指针解释获新生!!!
fn main() { let mut s = String::from("hello"); s.push_str(", world!"); println!("{}", s); let s1 = String::from("hello"); let (s2, len) = calculate_len(s1); println!("The len of '{}' is {}.", s2, len); let s1 = String::from("hello"); let len = calculate_length(&s1); println!("The length of '{}' is {}.", s1, len); } fn calculate_len(s: String) -> (String, usize) { let length = s.len(); (s, length) } fn calculate_length(s: &String) -> usize { s.len() }