pub trait CharsetCodec {
type Unit: Copy + Default;
// Required methods
fn charset(&self) -> Charset;
fn max_units_per_char(&self) -> usize;
fn decode_one(
&self,
input: &[Self::Unit],
index: usize,
) -> CharsetDecodeResult<DecodeStatus>;
fn encode_one(
&self,
ch: char,
output: &mut [Self::Unit],
index: usize,
) -> CharsetEncodeResult<usize>;
}Expand description
Low-level charset algorithm for one storage-unit representation.
CharsetCodec performs only primitive per-character encoding and decoding.
Policy decisions such as replacement, ignoring malformed input, or reporting
unmappable characters are handled by crate::CharsetDecoder and
crate::CharsetEncoder.
§Associated Types
Unit: Storage unit used by the encoded representation, such asu8for byte-oriented charsets,u16for UTF-16 code units, oru32for UTF-32 code units.
Required Associated Types§
Required Methods§
Sourcefn max_units_per_char(&self) -> usize
fn max_units_per_char(&self) -> usize
Returns the maximum number of storage units needed for one character.
§Returns
Returns an upper bound for one encoded Unicode scalar value.
Sourcefn decode_one(
&self,
input: &[Self::Unit],
index: usize,
) -> CharsetDecodeResult<DecodeStatus>
fn decode_one( &self, input: &[Self::Unit], index: usize, ) -> CharsetDecodeResult<DecodeStatus>
Decodes one Unicode scalar value from input starting at index.
§Parameters
input: Complete input unit slice.index: Absolute input unit index where decoding starts.
§Returns
Returns DecodeStatus::Complete when one scalar value is available.
Returns DecodeStatus::NeedMore when the current prefix is valid but
incomplete.
§Errors
Returns crate::CharsetDecodeError when the sequence at index is
malformed or decodes to a non-scalar value.
Sourcefn encode_one(
&self,
ch: char,
output: &mut [Self::Unit],
index: usize,
) -> CharsetEncodeResult<usize>
fn encode_one( &self, ch: char, output: &mut [Self::Unit], index: usize, ) -> CharsetEncodeResult<usize>
Encodes one Unicode scalar value into output starting at index.
§Parameters
ch: Unicode scalar value to encode.output: Complete output unit slice.index: Absolute output unit index where writing starts.
§Returns
Returns the number of output units written.
§Errors
Returns crate::CharsetEncodeError when ch cannot be represented by
this charset or output does not have enough capacity from index.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".