More efficient conversion from utf8 bytes to a string?

Just a small remark regarding terminology: What you likely meant is a Unicode Code Point or Unicode Scalar Value (opposed to a Grapheme Cluster or EGC). But maybe I misunderstood something?

Grapheme clusters might not fit into a 32 bit integer. (And code points that aren't a Unicode Scalar Value can't be converted into a Rust str.) See also Rust's primitive char type:

Primitive Type char

A character type.

The char type represents a single character. More specifically, since ‘character’ isn’t a well-defined concept in Unicode, char is a ‘Unicode scalar value’.

For the difference between a code point and a grapheme cluster, see Unicode Standard Annex #29.


See also Primitive str::chars, which clarifies:

It’s important to remember that char represents a Unicode Scalar Value, and might not match your idea of what a ‘character’ is. Iteration over grapheme clusters may be what you actually want. This functionality is not provided by Rust’s standard library, check crates.io instead.