EncodeBuilder

Struct EncodeBuilder 

Source
pub struct EncodeBuilder<'a, I>
where I: AsRef<[u8]>,
{ /* private fields */ }
Expand description

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

Implementations§

Source§

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

Source

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

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

Source

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

Change the alphabet that will be used for encoding.

§Examples
let input = [0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78];
assert_eq!(
    "he11owor1d",
    bs58::encode(input)
        .with_alphabet(bs58::Alphabet::RIPPLE)
        .into_string());
Source

pub fn into_string(self) -> String

Encode into a new owned string.

§Examples
let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58];
assert_eq!("he11owor1d", bs58::encode(input).into_string());
Source

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

Encode into a new owned vector.

§Examples
let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58];
assert_eq!(b"he11owor1d", &*bs58::encode(input).into_vec());
Source

pub fn into(self, output: impl EncodeTarget) -> Result<usize, Error>

Encode into the given buffer.

Returns the length written into the buffer.

If the buffer is resizeable it will be reallocated to fit the encoded data and truncated to size.

If the buffer is not resizeable bytes after the final character will be left alone, except up to 3 null bytes may be written to an &mut str to overwrite remaining characters of a partially overwritten multi-byte character.

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

§Examples
§Vec<u8>
let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58];
let mut output = "goodbye world".to_owned().into_bytes();
bs58::encode(input).into(&mut output)?;
assert_eq!(b"he11owor1d", &*output);
§&mut [u8]
let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58];
let mut output = Vec::from("goodbye world");
bs58::encode(input).into(&mut output[..])?;
assert_eq!(b"he11owor1drld", &*output);
§String
let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58];
let mut output = "goodbye world".to_owned();
bs58::encode(input).into(&mut output)?;
assert_eq!("he11owor1d", output);
§&mut str
let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58];
let mut output = "goodbye world".to_owned();
bs58::encode(input).into(output.as_mut_str())?;
assert_eq!("he11owor1drld", output);
§Clearing partially overwritten characters
let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58];
let mut output = "goodbye w®ld".to_owned();
bs58::encode(input).into(output.as_mut_str())?;
assert_eq!("he11owor1d\0ld", output);

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, I> UnwindSafe for EncodeBuilder<'a, I>
where I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> AbiExample for T

Source§

default fn example() -> T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V