Struct bs58::decode::DecodeBuilder

source ·
pub struct DecodeBuilder<'a, I: AsRef<[u8]>> { /* private fields */ }
Expand description

A builder for setting up the alphabet and output of a base58 decode.

See the documentation for bs58::decode for a more high level view of how to use this.

Implementations§

source§

impl<'a, I: AsRef<[u8]>> DecodeBuilder<'a, I>

source

pub const fn new(input: I, alpha: &'a Alphabet) -> DecodeBuilder<'a, I>

Setup decoder for the given string using the given alphabet. Preferably use bs58::decode instead of this directly.

source

pub const fn with_alphabet(self, alpha: &'a Alphabet) -> DecodeBuilder<'a, I>

Change the alphabet that will be used for decoding.

§Examples
assert_eq!(
    vec![0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78],
    bs58::decode("he11owor1d")
        .with_alphabet(bs58::Alphabet::RIPPLE)
        .into_vec()?);
source

pub fn into_vec(self) -> Result<Vec<u8>>

Decode into a new vector of bytes.

See the documentation for bs58::decode for an explanation of the errors that may occur.

§Examples
assert_eq!(
    vec![0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58],
    bs58::decode("he11owor1d").into_vec()?);
source

pub fn onto(self, output: impl DecodeTarget) -> Result<usize>

Decode into the given buffer.

Returns the length written into the buffer.

If the buffer is resizeable it will be extended and the new data will be written to the end of it.

If the buffer is not resizeable bytes will be written from the beginning and bytes after the final encoded byte will not be touched.

See the documentation for bs58::decode for an explanation of the errors that may occur.

§Examples
§Vec<u8>
let mut output = b"hello ".to_vec();
assert_eq!(5, bs58::decode("EUYUqQf").onto(&mut output)?);
assert_eq!(b"hello world", output.as_slice());
§&mut [u8]
let mut output = b"hello ".to_owned();
assert_eq!(5, bs58::decode("EUYUqQf").onto(&mut output)?);
assert_eq!(b"world ", output.as_ref());
source§

impl<'a, 'b> DecodeBuilder<'a, &'b [u8]>

For const compatibility we are restricted to using a concrete input and output type, as const trait implementations and &mut are unstable. These methods will eventually be deprecated once the primary interfaces can be converted into const fn directly.

source

pub const fn into_array_const<const N: usize>(self) -> Result<[u8; N]>

Decode into a new array.

Returns the decoded array as bytes.

See the documentation for bs58::decode for an explanation of the errors that may occur.

§Examples
const _: () = {
    let Ok(output) = bs58::decode(b"EUYUqQf".as_slice()).into_array_const::<5>() else {
        panic!()
    };
    assert!(matches!(&output, b"world"));
};
source

pub const fn into_array_const_unwrap<const N: usize>(self) -> [u8; N]

Self::into_array_const but the result will be unwrapped, turning any error into a panic message via Error::unwrap_const, as a simple into_array_const().unwrap() isn’t possible yet.

§Examples
const _: () = {
    let output: [u8; 5] = bs58::decode(b"EUYUqQf".as_slice()).into_array_const_unwrap();
    assert!(matches!(&output, b"world"));
};
const _: () = {
    assert!(matches!(
        bs58::decode(b"he11owor1d".as_slice())
            .with_alphabet(bs58::Alphabet::RIPPLE)
            .into_array_const_unwrap(),
        [0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78],
    ));
};

Auto Trait Implementations§

§

impl<'a, I> Freeze for DecodeBuilder<'a, I>
where I: Freeze,

§

impl<'a, I> RefUnwindSafe for DecodeBuilder<'a, I>
where I: RefUnwindSafe,

§

impl<'a, I> Send for DecodeBuilder<'a, I>
where I: Send,

§

impl<'a, I> Sync for DecodeBuilder<'a, I>
where I: Sync,

§

impl<'a, I> Unpin for DecodeBuilder<'a, I>
where I: Unpin,

§

impl<'a, I> UnwindSafe for DecodeBuilder<'a, I>
where I: 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> 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.