3 ms·
The Rust docs have good sections on this: https://doc.rust-lang.org/book/ch08-02-strings.html https://doc.rust-lang.org/book/ch08-02-strings.html https://doc.
by trevyn 7y ago
The Rust docs have good sections on this:
https://doc.rust-lang.org/book/ch08-02-strings.html https://doc.rust-lang.org/book/ch08-02-strings.html
https://doc.rust-lang.org/std/primitive.char.html https://doc.rust-lang.org/std/primitive.char.html
TLDR you can straightforwardly access as bytes, or iterate as "Unicode scalar values" as stored in the 4-byte "char" type.
(But a "Unicode scalar value" is not exactly equal to the colloquial meaning of "character".)
However: If you care about valid UTF-8 inputs not breaking the function or intent of your code, it's probably time to understand the problems Unicode is actually trying to address, and apply those considerations to what you're trying to do. :)