4 ms·
somewhat of a rust noob: but as I recall there is a difference between string and array of chars. string use utf-8, which is 1 byte for the most common charact
by pelliphant 6y ago
somewhat of a rust noob: but as I recall there is a difference between string and array of chars.
string use utf-8, which is 1 byte for the most common characters.
char is unicode
- ChrisSD 6y agoThey are both unicode. A `String` is unicode encoded as `UTF-8` whereas a `char` is simply a single, un-encoded, code point. An array of `char` would technically be UTF-32. Which isn't particularly useful, imho.
- pelliphant 6y agook, thnx for clarifying.
- Tobu 6y agoA char is a scalar value, rather: https://doc.rust-lang.org/std/primitive.char.html https://doc.rust-lang.org/std/primitive.char.html
- ChrisSD 6y agoYou're right, of course. Unicode terminology always trips me up. I have to remember that a scalar value is almost the same as a code point except that it excludes surrogates.