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.).
Required Methods§
Sourcefn decode<'t, IN: AsRef<[u8]>>(
bin: &'t mut [u8],
encoded: IN,
ignore: Option<&[u8]>,
) -> Result<&'t [u8], Error>
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.
§Arguments
bin
- Mutable buffer to store the decoded outputencoded
- Text input data to decodeignore
- Optional set of characters to ignore during decoding (e.g., whitespace)
§Returns
Ok(&[u8])
- A slice of the binary buffer containing the decoded dataErr(Error::Overflow)
- If the output buffer is too smallErr(Error::InvalidInput)
- If the input contains invalid characters
Provided Methods§
Sourcefn decode_to_vec<IN: AsRef<[u8]>>(
encoded: IN,
ignore: Option<&[u8]>,
) -> Result<Vec<u8>, Error>
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 decodeignore
- Optional set of characters to ignore during decoding (e.g., whitespace)
§Returns
Ok(Vec<u8>)
- A Vec containing the decoded binary dataErr(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", so this trait is not object safe.