Struct const_decoder::Encoding

source ·
pub struct Encoding { /* private fields */ }
Expand description

Custom encoding scheme based on a certain alphabet (mapping between a subset of ASCII chars and digits in 0..P, where P is a power of 2).

Examples

// Decoder for Bech32 encoding as specified in
// https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki.
const BECH32: Decoder = Decoder::custom("qpzry9x8gf2tvdw0s3jn54khce6mua7l");

// Sample address from the Bech32 spec excluding the `tb1q` prefix
// and the checksum suffix.
const SAMPLE_ADDR: [u8; 32] =
    BECH32.decode(b"rp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q");

Implementations§

source§

impl Encoding

source

pub const fn new(alphabet: &'static str) -> Self

Creates an encoding based on the provided alphabet: a sequence of ASCII chars that correspond to digits 0, 1, 2, etc.

Panics
  • Panics if alphabet does not consist of distinct ASCII chars.
  • Panics if alphabet length is not 2, 4, 8, 16, 32 or 64.

Trait Implementations§

source§

impl Clone for Encoding

source§

fn clone(&self) -> Encoding

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 Debug for Encoding

source§

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

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

impl Copy for Encoding

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.