I have just started with Rust, and I have just reached the end of the section on control flow in the Rust Programming Language Textbook.
I have been playing around with some of the concepts that have been introduced thus far, but I have ran into an issue with strings.
I might be a bit… erm… Rusty (ahem*), but I think in C++ I could do something like:
std::string my_string = ""; my_string = "This is my amazing string.";
With Rust, when I try:
let mut my_string = String::new(); my_str = "This is my amazing string";
"my_string = "This is my amazing string."; expected struct `std::string::String`, found reference help: try using a conversion method: `"This is my amazing string.".to_string()`"
It found a reference, and I need to try converting my_string to a string?
In the examples so far in the textbook, it appears that the original empty string is just shadowed. Something like:
let mut my_string = String::new(); let mut my_string = "This is my amazing string.";
In Listing 2-5 from the textbook, it actually replaces the string with a new string:
let mut guess = String::new();
Everytime it loops back around, but I guess the principle is the same?
Some of these concepts are new to me, so I appreciate your help (I am currently only up to the section on ownership, so any concepts beyond this would not be familiar to me).
*I am aware this pun has probably been used ad nauseum, I apologise profusely.