Codec

Struct Codec 

Source
pub struct Codec<'a> { /* private fields */ }
Expand description

BASE64 codec

Implementations§

Source§

impl<'a> Codec<'a>

Source

pub unsafe fn encode_to_raw( &self, src: &[u8], dst: NonNull<u8>, len: &mut usize, ) -> bool

Raw encoding function.

§Arguments
  • src - Input to encode;
  • dst - Output to write;
  • len - Output length, modified with required size regardless of outcome, unless calculation wrapping happens.
§Result

Returns true on success.

Returns false if buffer overflow would to happen or required_len is too big.

Source

pub unsafe fn decode_to_raw( &self, src: &[u8], dst: NonNull<u8>, len: &mut usize, ) -> bool

Raw decoding function.

§Arguments
  • src - Input to decode;
  • dst - Output to write;
  • len - Output length, modified with required size regardless of outcome.
§Result

Returns true on success.

Returns false if buffer overflow would to happen or src is empty or invalid base64.

Source§

impl<'a> Codec<'a>

Source

pub fn encode_to_uninit( self, src: &[u8], dst: &mut [MaybeUninit<u8>], ) -> Option<usize>

Encoding function writing to uninit slice.

§Arguments
  • src - Input to encode;
  • dst - Output to write;
§Result

Returns Some if successful, containing number of bytes written.

Returns None if data cannot be encoded due to insufficient buffer size or size calculation overflow happens.

Source

pub fn decode_to_uninit( &self, src: &[u8], dst: &mut [MaybeUninit<u8>], ) -> Option<usize>

Decoding function writing to uninit slice.

§Arguments
  • src - Input to decode;
  • dst - Output to write;
§Result

Returns Some if successful, containing number of bytes written.

Returns None if data cannot be encoded due to insufficient buffer size or invalid input.

Source§

impl<'a> Codec<'a>

Source

pub fn encode_into_vec(&self, src: &[u8]) -> Vec<u8>

Encoding function returns vector with data written.

Requires feature alloc.

§Arguments
  • src - Input to encode;
§Panics

In case of required size to be too big

Source

pub fn decode_into_vec(&self, src: &[u8]) -> Option<Vec<u8>>

Decoding function returns vector with data written.

Requires feature alloc.

§Arguments
  • src - Input to decode;
§Result

Returns Some if successful, containing decoded output

Returns None if src is invalid input.

Source§

impl<'a> Codec<'a>

Source

pub fn encode_into_string(&self, src: &[u8]) -> String

Encoding function returns string.

Requires feature alloc.

§Arguments
  • src - Input to encode;
§Panics

In case of required size to be too big or table contains non-ASCII characters

Source§

impl<'a> Codec<'a>

Source

pub const fn new(table: &'a [u8; 64]) -> Self

Creates new codec, validating that table contains only ASCII characters.

Source

pub fn standard() -> &'static Codec<'static>

Access prebuilt instance of codec with STANDARD_TABLE

Source

pub fn url_usafe() -> &'static Codec<'static>

Access prebuilt instance of codec with URL_TABLE

Source§

impl<'a> Codec<'a>

Source

pub fn encode_to(&self, src: &[u8], dst: &mut [u8]) -> Option<usize>

Encoding function writing to slice.

§Arguments
  • src - Input to encode;
  • dst - Output to write;
§Result

Returns Some if successful, containing number of bytes written.

Returns None if data cannot be encoded due to insufficient buffer size or size calculation overflow happens.

Source

pub fn decode_to(&self, src: &[u8], dst: &mut [u8]) -> Option<usize>

Decoding function writing to slice.

§Arguments
  • src - Input to decode;
  • dst - Output to write;
§Result

Returns Some if successful, containing number of bytes written.

Returns None if data cannot be encoded due to insufficient buffer size or invalid input.

Trait Implementations§

Source§

impl<'a> Clone for Codec<'a>

Source§

fn clone(&self) -> Codec<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Codec<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Codec<'a>

§

impl<'a> RefUnwindSafe for Codec<'a>

§

impl<'a> Send for Codec<'a>

§

impl<'a> Sync for Codec<'a>

§

impl<'a> Unpin for Codec<'a>

§

impl<'a> UnwindSafe for Codec<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.