4 ms·
Similar, except for this key difference: > A substring holds a reference to the entire storage of the string it comes from, not just to the portion it presents
by iamed2 8y ago
Similar, except for this key difference:
> A substring holds a reference to the entire storage of the string it comes from, not just to the portion it presents, even when there is no other reference to the original string.
Rust's `&str` doesn't do that, since the borrow checker will ensure at compile time that the `&str` reference doesn't live longer than the data it points to. At runtime there is no structural difference between an "original" `&str` and a `&str` pointing to a substring of the original.