Rust has String (owned, growable UTF-8) and &str (borrowed slice). String literals are &'static str. Indexing by byte can panic—use chars or graphemes for Unicode.
Building strings
let mut s = String::from("Hello");
s.push_str(", Rust!");
Important interview questions and answers
- Q: Why not index String like an array of chars?
A: UTF-8 is variable-width—byte index may split a character.
Self-check
- Owned vs borrowed string types?
- Are Rust strings UTF-8?