Why does this dosen’t work
shouldn’t the print macro print in both the cases
would really appreciate a nice explanation,
borrow-checker’s really got to my head coming from java
fn main() {
let mut s1 = String::from("Hello");
let s2 = &mut s1;
let s3 = update_word(s2);
println!("{}", s2);
println!("{}", s3);
}
fn update_word(word: &mut String) -> &str {
word.push_str(" World");
return "Hello";
}
and this does
fn main() {
let mut s1 = String::from("Hello");
let s2 = &mut s1;
let s3 = update_word(s2);
println!("{}", s3);
println!("{}", s2);
}
fn update_word(word: &mut String) -> &str {
word.push_str(" World");
return "Hello";
}
Gave error in first and works on seccond