Skip to main content

Utf8Handler

Trait Utf8Handler 

Source
pub trait Utf8Handler {
    type Output;

    // Required methods
    fn single_byte(&self, ascii: Ascii) -> Self::Output;
    fn two_byte(&self, sequence: TwoByteSequence) -> Self::Output;
    fn three_byte(&self, sequence: ThreeByteSequence) -> Self::Output;
    fn four_byte(&self, sequence: FourByteSequence) -> Self::Output;

    // Provided method
    fn error(&self) -> Self::Output { ... }
}
Expand description

Mapping from the four kinds of byte sequences or error to output.

Required Associated Types§

Source

type Output

The per-scalar-value output type. (In the common case, this is char.)

Required Methods§

Source

fn single_byte(&self, ascii: Ascii) -> Self::Output

Map a single-byte UTF-8 sequence to Output.

When Output is char, ascii.to_char() is the appropriate implementation.

The implementation is expected to be marked #[inline(always)].

Source

fn two_byte(&self, sequence: TwoByteSequence) -> Self::Output

Map a two-byte UTF-8 sequence to Output.

When Output is char, sequence.to_char() is the appropriate implementation.

The implementation is expected to be marked #[inline(always)].

Source

fn three_byte(&self, sequence: ThreeByteSequence) -> Self::Output

Map a three-byte UTF-8 sequence to Output.

When Output is char, sequence.to_char() is the appropriate implementation.

The implementation is expected to be marked #[inline(always)].

Source

fn four_byte(&self, sequence: FourByteSequence) -> Self::Output

Map a four-byte UTF-8 sequence to Output.

When Output is char, sequence.to_char() is the appropriate implementation.

The implementation is expected to be marked #[inline(always)].

Provided Methods§

Source

fn error(&self) -> Self::Output

Map a single UTF-8 error to Output.

What constitutes a single error is defined by the WHATWG Encoding Standard.

When Output is char, char::REPLACEMENT_CHARACTER is the appropriate implementation. The provided implementation delegates to three_byte by passing the three bytes that represent the REPLACEMENT CHARACTER.

The implementation of this method is expected to be declared #[inline(always)].

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§