3 ms·
Indeed &str has as_bytes which returns itself as &[u8] But, str is a subset of &[u8], the type's contract is that it is unsafe to have non valid UTF-8 data, he
by __s 6y ago
Indeed &str has as_bytes which returns itself as &[u8]
But, str is a subset of &[u8], the type's contract is that it is unsafe to have non valid UTF-8 data, hence https://doc.rust-lang.org/std/str/fn.from_utf8.html https://doc.rust-lang.org/std/str/fn.from_utf8.html can error, offering the unsafe variant https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked.html https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked.htm...
This is all very different than &[char] which would be an array of 4 byte characters (or, a UCS4 string)