Struct Utf8Chunk
struct Utf8Chunk<'a> { ... }
An item returned by the Utf8Chunks iterator.
A Utf8Chunk stores a sequence of u8 up to the first broken character
when decoding a UTF-8 string.
Examples
// An invalid UTF-8 string
let bytes = b"foo\xF1\x80bar";
// Decode the first `Utf8Chunk`
let chunk = bytes.utf8_chunks.next.unwrap;
// The first three characters are valid UTF-8
assert_eq!;
// The fourth character is broken
assert_eq!;
Implementations
impl<'a> Utf8Chunk<'a>
fn valid(self: &Self) -> &'a strReturns the next validated UTF-8 substring.
This substring can be empty at the start of the string or between broken UTF-8 characters.
fn invalid(self: &Self) -> &'a [u8]Returns the invalid sequence that caused a failure.
The returned slice will have a maximum length of 3 and starts after the substring given by
valid. Decoding will resume after this sequence.If empty, this is the last chunk in the string. If non-empty, an unexpected byte was encountered or the end of the input was reached unexpectedly.
Lossy decoding would replace this sequence with
U+FFFD REPLACEMENT CHARACTER.
impl<'a> Clone for Utf8Chunk<'a>
fn clone(self: &Self) -> Utf8Chunk<'a>
impl<'a> Debug for Utf8Chunk<'a>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<'a> Eq for Utf8Chunk<'a>
impl<'a> Freeze for Utf8Chunk<'a>
impl<'a> PartialEq for Utf8Chunk<'a>
fn eq(self: &Self, other: &Utf8Chunk<'a>) -> bool
impl<'a> RefUnwindSafe for Utf8Chunk<'a>
impl<'a> Send for Utf8Chunk<'a>
impl<'a> StructuralPartialEq for Utf8Chunk<'a>
impl<'a> Sync for Utf8Chunk<'a>
impl<'a> Unpin for Utf8Chunk<'a>
impl<'a> UnsafeUnpin for Utf8Chunk<'a>
impl<'a> UnwindSafe for Utf8Chunk<'a>
impl<T> Any for Utf8Chunk<'a>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Utf8Chunk<'a>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Utf8Chunk<'a>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Utf8Chunk<'a>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Utf8Chunk<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Utf8Chunk<'a>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Utf8Chunk<'a>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Utf8Chunk<'a>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>