Rust theorytheory 0/50 · 0%
Fundamentals · easy

10. String and &str

Two string types and why.

`&str` is a borrowed immutable UTF-8 slice; `String` is an owned growable buffer. Convert with `to_string()` and borrow back via deref coercion. Byte indexing is disallowed because UTF-8 characters vary in width; use `.chars()` instead.

Check your understanding

  1. 1. Which is owned and growable?

  2. 2. Why is s[0] rejected?