Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder {
    // Required method
    fn decode<'t, IN: AsRef<[u8]>>(
        bin: &'t mut [u8],
        encoded: IN,
        ignore: Option<&[u8]>,
    ) -> Result<&'t [u8], Error>;

    // Provided method
    fn decode_to_vec<IN: AsRef<[u8]>>(
        encoded: IN,
        ignore: Option<&[u8]>,
    ) -> Result<Vec<u8>, Error> { ... }
}
Expand description

Trait for decoding text representations back into binary data.

Implementors of this trait provide constant-time decoding operations for a specific encoding format (Base64, Hex, etc.). By default, decoders require the canonical alphabet for the selected variant; only bytes explicitly listed in ignore are skipped.

Required Methods§

Source

fn decode<'t, IN: AsRef<[u8]>>( bin: &'t mut [u8], encoded: IN, ignore: Option<&[u8]>, ) -> Result<&'t [u8], Error>

Decodes text data back into its binary representation.

This method rejects non-canonical encodings, invalid padding, and characters outside the selected variant’s alphabet unless they are explicitly listed in ignore.

§Arguments
  • bin - Mutable buffer to store the decoded output
  • encoded - Text input data to decode
  • ignore - Optional set of characters to ignore during decoding (e.g., whitespace)
§Returns
  • Ok(&[u8]) - A slice of the binary buffer containing the decoded data
  • Err(Error::Overflow) - If the output buffer is too small
  • Err(Error::InvalidInput) - If the input contains invalid characters

Provided Methods§

Source

fn decode_to_vec<IN: AsRef<[u8]>>( encoded: IN, ignore: Option<&[u8]>, ) -> Result<Vec<u8>, Error>

Decodes text data and returns the result as a Vec.

This method is only available when the std feature is enabled.

§Arguments
  • encoded - Text input data to decode
  • ignore - Optional set of characters to ignore during decoding (e.g., whitespace)
§Returns
  • Ok(Vec<u8>) - A Vec containing the decoded binary data
  • Err(Error::InvalidInput) - If the input contains invalid characters

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§