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.
Given a byte slice, determine whether it is valid for the current encoding.
Take a character and encode it directly into the provided buffer. If successful, returns the
length of the buffer that was written.
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.