Utf8Chunk in std::str - Rust (original) (raw)

Struct Utf8Chunk

1.79.0 · Source

pub struct Utf8Chunk<'a> { /* private fields */ }

Expand description

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!("foo", chunk.valid());

// The fourth character is broken
assert_eq!(b"\xF1\x80", chunk.invalid());

Source§

1.79.0 · Source

Returns the next validated UTF-8 substring.

This substring can be empty at the start of the string or between broken UTF-8 characters.

1.79.0 · Source

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.

1.79.0 · Source§

1.79.0 · Source§

1.79.0 · Source§

Source§

Tests for self and other values to be equal, and is used by ==.

1.0.0 · Source§

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

1.79.0 · Source§

1.79.0 · Source§

§

§

§

§

§

§