Function decode
fn decode<B: AsRef<[u8]>>(slice: B) -> (Option<char>, usize)
UTF-8 decode a single Unicode scalar value from the beginning of a slice.
When successful, the corresponding Unicode scalar value is returned along with the number of bytes it was encoded with. The number of bytes consumed for a successful decode is always between 1 and 4, inclusive.
When unsuccessful, None is returned along with the number of bytes that
make up a maximal prefix of a valid UTF-8 code unit sequence. In this case,
the number of bytes consumed is always between 0 and 3, inclusive, where
0 is only returned when slice is empty.
Examples
Basic usage:
use decode_utf8;
// Decoding a valid codepoint.
let = decode_utf8;
assert_eq!;
assert_eq!;
// Decoding an incomplete codepoint.
let = decode_utf8;
assert_eq!;
assert_eq!;
This example shows how to iterate over all codepoints in UTF-8 encoded bytes, while replacing invalid UTF-8 sequences with the replacement codepoint:
use ;
let mut bytes = B;
let mut chars = vec!;
while !bytes.is_empty
assert_eq!;