Module std::encoding::utf8

Validating and lossy UTF-8 decoding with explicit byte-position errors.

Contents

Functions

Function decode

pub fn decode(data: bytes) -> string fails Utf8Error

Decode UTF-8 bytes, returning the first byte-position error as ordinary Result data. Valid input preserves every Unicode scalar, including NUL.

Function decode_lossy

pub fn decode_lossy(data: bytes) -> string

Decode UTF-8 bytes and replace malformed sequences with U+FFFD.

Types

Struct Utf8Error

Details of invalid UTF-8 in an encoded byte sequence.

Fields

valid_up_to: i64

Number of valid bytes before the invalid or incomplete sequence.

error_len: Option<i64>

Invalid sequence length in bytes, or None for incomplete trailing input.