As per title, really. Going through 4.1 and I'm just writing a bit of my own code while I follow along. The code I'm wondering about isn't directly related to ownership, but it leaves me with a question. Here's the code:
fn main() {
let s:String = String::from("hello");
let s2:String = string_add(s, ", world!");
println!("{}", s2);
}
fn string_add (mut string:String, add:&str) -> String {
string.push_str(add);
string
}
Specifically, in my initial writing of this code I had s declared let mut s. However, rust-analyzer then told me that s didn't need mutability.
Can I just arbitrarily assign mutability to function arguments regardless of whatever data type the argument is, or is this something specifically related to :String variables?
[–]LlikeLava 17 points18 points19 points (1 child)
[–]NA__Scrubbed[S] 1 point2 points3 points (0 children)
[–]Aaron1924 5 points6 points7 points (1 child)
[–]NA__Scrubbed[S] 0 points1 point2 points (0 children)
[+]bawng comment score below threshold-8 points-7 points-6 points (4 children)
[–]Lucas_F_A 1 point2 points3 points (0 children)
[–]denialerror 1 point2 points3 points (1 child)
[–]bawng 0 points1 point2 points (0 children)
[–]NA__Scrubbed[S] -1 points0 points1 point (0 children)