Struct Encoding

Source
pub struct Encoding<Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> { /* private fields */ }
Expand description

Base-conversion encoding.

See Specification for technical details or how to define a new one.

Implementations§

Source§

impl<Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> Encoding<Bit, Msb, Pad, Wrap, Ignore>

Source

pub fn encode_len(&self, len: usize) -> usize

Returns the encoded length of an input of length len.

See Self::encode_mut() for when to use it.

Source

pub fn encode_mut_uninit<'a>( &self, input: &[u8], output: &'a mut [MaybeUninit<u8>], ) -> &'a mut [u8]

Encodes input in output.

§Panics

Panics if the output length does not match the result of Self::encode_len() for the input length.

Source

pub fn encode_mut(&self, input: &[u8], output: &mut [u8])

Encodes input in output.

§Panics

Panics if the output length does not match the result of Self::encode_len() for the input length.

Source

pub fn encode_append(&self, input: &[u8], output: &mut String)

Available on crate feature alloc only.

Appends the encoding of input to output.

Source

pub fn encode_write_buffer_uninit( &self, input: &[u8], output: &mut impl Write, buffer: &mut [MaybeUninit<u8>], ) -> Result

Writes the encoding of input to output using a temporary buffer.

§Panics

Panics if the buffer is shorter than 510 bytes.

§Errors

Returns an error when writing to the output fails.

Source

pub fn encode_write_buffer( &self, input: &[u8], output: &mut impl Write, buffer: &mut [u8], ) -> Result

Writes the encoding of input to output using a temporary buffer.

§Panics

Panics if the buffer is shorter than 510 bytes.

§Errors

Returns an error when writing to the output fails.

Source

pub fn encode_write(&self, input: &[u8], output: &mut impl Write) -> Result

Writes the encoding of input to output.

This allocates a buffer of 1024 bytes on the stack. If you want to control the buffer size and location, use Self::encode_write_buffer() instead.

§Errors

Returns an error when writing to the output fails.

Source

pub fn encode(&self, input: &[u8]) -> String

Available on crate feature alloc only.

Returns encoded input.

Source

pub fn decode_len(&self, len: usize) -> Result<usize, DecodeError>

Returns the decoded length of an input of length len.

See Self::decode_mut() for when to use it.

§Errors

Returns an error if len is invalid. The error kind is DecodeKind::Length and the error position is the greatest valid input length.

Source

pub fn decode_mut_uninit<'a>( &self, input: &[u8], output: &'a mut [MaybeUninit<u8>], ) -> Result<&'a mut [u8], DecodePartial>

Decodes input in output.

Returns the decoded output. Its length may be smaller than the output length if the input contained padding or ignored characters. The output bytes after the returned length are not initialized and should not be read.

§Panics

Panics if the output length does not match the result of Self::decode_len() for the input length. Also panics if decode_len fails for the input length.

§Errors

Returns an error if input is invalid. See Self::decode_mut() for more details.

Source

pub fn decode_mut( &self, input: &[u8], output: &mut [u8], ) -> Result<usize, DecodePartial>

Decodes input in output.

Returns the length of the decoded output. This length may be smaller than the output length if the input contained padding or ignored characters. The output bytes after the returned length are not initialized and should not be read.

§Panics

Panics if the output length does not match the result of Self::decode_len() for the input length. Also panics if decode_len fails for the input length.

§Errors

Returns an error if input is invalid. See Self::decode() for more details. The are two differences though:

Source

pub fn decode(&self, input: &[u8]) -> Result<Vec<u8>, DecodeError>

Available on crate feature alloc only.

Returns decoded input.

§Errors

Returns an error if input is invalid. The error kind can be:

  • DecodeKind::Length if the input length is invalid. The position is the greatest valid input length.
  • DecodeKind::Symbol if the input contains an invalid character. The position is the first invalid character.
  • DecodeKind::Trailing if the input has non-zero trailing bits. This is only possible if the encoding checks trailing bits. The position is the first character containing non-zero trailing bits.
  • DecodeKind::Padding if the input has an invalid padding length. This is only possible if the encoding uses padding. The position is the first padding character of the first padding of invalid length.
Source

pub fn specification(&self) -> Specification

Available on crate feature alloc only.

TODO

Source

pub fn as_dyn(&self) -> &DynEncoding

TODO

Trait Implementations§

Source§

impl<Bit: Clone + BitWidth, Msb: Clone + Bool, Pad: Clone + Bool, Wrap: Clone + Bool, Ignore: Clone + Bool> Clone for Encoding<Bit, Msb, Pad, Wrap, Ignore>

Source§

fn clone(&self) -> Encoding<Bit, Msb, Pad, Wrap, Ignore>

Returns a copy 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<Bit: Debug + BitWidth, Msb: Debug + Bool, Pad: Debug + Bool, Wrap: Debug + Bool, Ignore: Debug + Bool> Debug for Encoding<Bit, Msb, Pad, Wrap, Ignore>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> From<&'a Encoding<Bit, Msb, Pad, Wrap, Ignore>> for &'a DynEncoding

Source§

fn from(base: &'a Encoding<Bit, Msb, Pad, Wrap, Ignore>) -> Self

Converts to this type from the input type.
Source§

impl<Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> From<Encoding<Bit, Msb, Pad, Wrap, Ignore>> for DynEncoding

Source§

fn from(base: Encoding<Bit, Msb, Pad, Wrap, Ignore>) -> Self

Converts to this type from the input type.
Source§

impl<Bit: PartialEq + BitWidth, Msb: PartialEq + Bool, Pad: PartialEq + Bool, Wrap: PartialEq + Bool, Ignore: PartialEq + Bool> PartialEq for Encoding<Bit, Msb, Pad, Wrap, Ignore>

Source§

fn eq(&self, other: &Encoding<Bit, Msb, Pad, Wrap, Ignore>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> TryFrom<&'a DynEncoding> for &'a Encoding<Bit, Msb, Pad, Wrap, Ignore>

Source§

type Error = ConvertError

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

fn try_from(base: &'a DynEncoding) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> TryFrom<DynEncoding> for Encoding<Bit, Msb, Pad, Wrap, Ignore>

Source§

type Error = ConvertError

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

fn try_from(base: DynEncoding) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<Bit: Eq + BitWidth, Msb: Eq + Bool, Pad: Eq + Bool, Wrap: Eq + Bool, Ignore: Eq + Bool> Eq for Encoding<Bit, Msb, Pad, Wrap, Ignore>

Source§

impl<Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> StructuralPartialEq for Encoding<Bit, Msb, Pad, Wrap, Ignore>

Auto Trait Implementations§

§

impl<Bit, Msb, Pad, Wrap, Ignore> Freeze for Encoding<Bit, Msb, Pad, Wrap, Ignore>

§

impl<Bit, Msb, Pad, Wrap, Ignore> RefUnwindSafe for Encoding<Bit, Msb, Pad, Wrap, Ignore>
where Bit: RefUnwindSafe, Msb: RefUnwindSafe, Pad: RefUnwindSafe, Wrap: RefUnwindSafe, Ignore: RefUnwindSafe,

§

impl<Bit, Msb, Pad, Wrap, Ignore> Send for Encoding<Bit, Msb, Pad, Wrap, Ignore>
where Bit: Send, Msb: Send, Pad: Send, Wrap: Send, Ignore: Send,

§

impl<Bit, Msb, Pad, Wrap, Ignore> Sync for Encoding<Bit, Msb, Pad, Wrap, Ignore>
where Bit: Sync, Msb: Sync, Pad: Sync, Wrap: Sync, Ignore: Sync,

§

impl<Bit, Msb, Pad, Wrap, Ignore> Unpin for Encoding<Bit, Msb, Pad, Wrap, Ignore>
where Bit: Unpin, Msb: Unpin, Pad: Unpin, Wrap: Unpin, Ignore: Unpin,

§

impl<Bit, Msb, Pad, Wrap, Ignore> UnwindSafe for Encoding<Bit, Msb, Pad, Wrap, Ignore>
where Bit: UnwindSafe, Msb: UnwindSafe, Pad: UnwindSafe, Wrap: UnwindSafe, Ignore: UnwindSafe,

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.