Strings are stored with a length instead of null terminator.
All strings are UTF-8.
Most strings are either:
- String. Heap allocated and growable. Owns the data.
- String is a wrapper around a Vec<u8>
- &str. A view into another string with a potentially shorter length. Read only.
“&str” is short for “&’static str”.
- A static lifetime.
- str’s size isn’t known at compile time so it has to be used as a reference with &.
let boxed_str: Box<str> = string.into_boxed_str();
- Owned string that won’t be modified further.
Rc<str>
- Reference counted immutable string slice.
Arc<str>
- Atomic reference counted immutable string slice.