Skip to main content

BytesEncoding

Trait BytesEncoding 

Source
pub trait BytesEncoding {
    type Error: Error;

    // Required methods
    fn encode<'a>(src: &[u8], dst: &'a mut str) -> Result<&'a str, Self::Error>;
    fn decode<'a>(src: &str, dst: &'a mut [u8]) -> Result<&'a [u8], Self::Error>;
    fn encoded_len(bytes: &[u8]) -> Result<usize, Self::Error>;
    fn decoded_len(bytes: &str) -> Result<usize, Self::Error>;
}
Expand description

Trait for specifying the encoding of bytes as strings, like hex or base64.

Required Associated Types§

Required Methods§

Source

fn encode<'a>(src: &[u8], dst: &'a mut str) -> Result<&'a str, Self::Error>

Encodes src into dst, returning the slice of dst that was written.

The caller must ensure that len(dst) >= encoded_len(src).unwrap().

Source

fn decode<'a>(src: &str, dst: &'a mut [u8]) -> Result<&'a [u8], Self::Error>

Decodes src into dst, returning the slice of dst that was written.

The caller must ensure that len(dst) >= decoded_len(src).unwrap().

Source

fn encoded_len(bytes: &[u8]) -> Result<usize, Self::Error>

Source

fn decoded_len(bytes: &str) -> Result<usize, Self::Error>

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§

Source§

impl<Enc: Encoding> BytesEncoding for B64Encoding<Enc>

Source§

impl<const ELC: bool, const DMC: bool> BytesEncoding for B16Encoding<ELC, DMC>