3 ms·
As a small nit, the reason Rust has pairs of types (String vs &str) is not due to mutability, but to allow references to substrings. A String is an allocated o
by andrewaylett 2y ago
As a small nit, the reason Rust has pairs of types (String vs &str) is not due to mutability, but to allow references to substrings.
A String is an allocated object, with a location and length. A str is a sequence of characters "somewhere", which is why you can only have references to str, never an actual str object. Cstr and Osstr are similar. You could use &[u8] instead of any of them, but the stronger types enforce some guarantees on what you'll find in the sequence.