-
Without parameter borrowing (moves str's ownership to called function)
let str = String::from("Hello"); function(str); // str cannot be used in this scope from this line onwards
-
With parameter borrowing, without mutability
strcan still be used in the scope it was declared in, butfunction()cannot change its value.let str = String::from("Hello"); function(&str); // str can still be used in this scope, because function() returned the ownership of str to this scope after returning
-
With parameter borrowing and mutability
Makes
strmutable, so its value can be changed infunction.let mut str = String::from("Hello"); function(&mut str); // str is now "Hello, world!" . . fn function(str: &mut String){ str.push(", world!"); }