Struct bs58::encode::EncodeBuilder[][src]

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

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

Implementations

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

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());

Change the alphabet that will be used for decoding.

Examples

let input = [0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78];
assert_eq!(
    "he11owor1d",
    bs58::encode(input)
        .with_prepared_alphabet(bs58::Alphabet::RIPPLE)
        .into_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());

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());

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.