3 ms·
Ha ha. Rust? I suppose it depends on the context of what you're trying to do. Edit: if it is Rust most of the time you'll want to use character iterators/map/f
by swsieber 7y ago
Ha ha. Rust? I suppose it depends on the context of what you're trying to do.
Edit: if it is Rust most of the time you'll want to use character iterators/map/filter/etc. Then benchmark.
- trevyn 7y agoThe 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. :)