Codec

Trait Codec 

Source
pub trait Codec {
    // Required methods
    fn encode<I: Bits, O: MutBits>(
        &self,
        input: I,
        output: &mut O,
    ) -> Result<usize, Error>;
    fn decode<I: Bits, O: MutBits>(
        &self,
        input: I,
        output: &mut O,
    ) -> Result<usize, Error>;

    // Provided methods
    fn encode_to_str<I: Bits>(&self, input: I) -> Result<String, Error> { ... }
    fn encode_to_vec<I: Bits>(&self, input: I) -> Result<Vec<u8>, Error> { ... }
    fn decode_to_str_lossy<I: Bits>(&self, input: I) -> Result<String, Error> { ... }
    fn decode_to_vec<I: Bits>(&self, input: I) -> Result<Vec<u8>, Error> { ... }
}
Expand description

Something that can encode or decode bytes to bytes

Required Methods§

Source

fn encode<I: Bits, O: MutBits>( &self, input: I, output: &mut O, ) -> Result<usize, Error>

Encodes the input, writing to output. Returns the total number of bytes written.

Source

fn decode<I: Bits, O: MutBits>( &self, input: I, output: &mut O, ) -> Result<usize, Error>

Decodes the input, writing to output. Returns the total number of bytes written.

Provided Methods§

Source

fn encode_to_str<I: Bits>(&self, input: I) -> Result<String, Error>

Available on crate feature alloc only.

Reads the entirety of the input in the raw format, and produces the encoded UTF-8 results in an owned string.

Source

fn encode_to_vec<I: Bits>(&self, input: I) -> Result<Vec<u8>, Error>

Available on crate feature alloc only.

Reads the entirety of the input in the raw format, and produces the encoded results in an owned Vec

Source

fn decode_to_str_lossy<I: Bits>(&self, input: I) -> Result<String, Error>

Available on crate feature alloc only.

Reads the entirety of input in coded format, and produces the results in an owned UTF-8 encoded string, dropping any non-UTF-8 characters.

Source

fn decode_to_vec<I: Bits>(&self, input: I) -> Result<Vec<u8>, Error>

Available on crate feature alloc only.

Reads the entirety of input in coded format, and produces the results in an owned Vec

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§