Trait enrede::encoding::Encoding

source ·
pub trait Encoding: Default + Sealed {
    // Required method
    fn validate(bytes: &[u8]) -> Result<(), ValidateError>;

    // Provided methods
    fn encode(char: char, out: &mut [u8]) -> Result<usize, EncodeError> { ... }
    fn recode<E: Encoding>(
        str: &Str<E>,
        out: &mut [u8],
    ) -> Result<usize, RecodeError> { ... }
}
Expand description

An arbitrary encoding. Examples include Utf8, Ascii, or Win1252.

This trait is sealed, and multiple internal items are unstable, preventing downstream implementations. If you want an encoding not currently supported, please open an issue.

Required Methods§

source

fn validate(bytes: &[u8]) -> Result<(), ValidateError>

Given a byte slice, determine whether it is valid for the current encoding.

Provided Methods§

source

fn encode(char: char, out: &mut [u8]) -> Result<usize, EncodeError>

Take a character and encode it directly into the provided buffer. If successful, returns the length of the buffer that was written.

source

fn recode<E: Encoding>( str: &Str<E>, out: &mut [u8], ) -> Result<usize, RecodeError>

Given a string in another encoding, re-encode it into this encoding character by character. On success, returns the length of the output that was written.

Object Safety§

This trait is not object safe.

Implementors§