- let
Literal strings in variables are immutable
- Literal strings and changeable strings are stored differently in Rust.
- Literal strings stored in a variable are immutable.
examples/variables/immutable-string/src/main.rs
fn main() { let text = "Hello World!"; println!("{}", text); text = "Something else"; println!("{}", text); }
error[E0384]: cannot assign twice to immutable variable `text` --> examples/intro/hello_world_in_immutable_variable.rs:4:5 | 2 | let text = "Hello World!"; | ---- | | | first assignment to `text` | help: consider making this binding mutable: `mut text` 3 | println!("{}", text); 4 | text = "Something else"; // cannot assign twice to immutable variable | ^^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable error: aborting due to previous error For more information about this error, try `rustc --explain E0384`.