- 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` --> src/main.rs:5:5 | 2 | let text = "Hello World!"; | ---- | | | first assignment to `text` | help: consider making this binding mutable: `mut text` ... 5 | text = "Something else"; | ^^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable For more information about this error, try `rustc --explain E0384`. error: could not compile `immutable-string` (bin "immutable-string") due to 1 previous error