3 ms·
Another: String is inmutable AND whole. &[T] is parts, and when declared as &mut [T] is mutable. Because unicode, &[T] make easy to write wrong code (that asum
by mamcx 6y ago
Another: String is inmutable AND whole. &[T] is parts, and when declared as &mut [T] is mutable.
Because unicode, &[T] make easy to write wrong code (that asume here T = Char).
It CAN'T be Char, because char is larger than u8:
https://doc.rust-lang.org/std/primitive.char.html https://doc.rust-lang.org/std/primitive.char.html
and it mean unicode point.
In other words: Rust is using types to PREVENT the wrong behavior.
- pornel 6y agoFun fact: `&mut str` exists. You don't get random access, but in controlled scenarios it's fine to mutate str in-place, e.g. `make_ascii_lowercase` https://doc.rust-lang.org/stable/std/primitive.str.html#method.make_ascii_lowercase https://doc.rust-lang.org/stable/std/primitive.str.html#meth...