kvarn_utils::prelude::str

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());

Implementations§

source§

impl<'a> Utf8Chunk<'a>

1.79.0 · source

pub fn valid(&self) -> &'a str

Returns the next validated UTF-8 substring.

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

<