Skip to content

Instantly share code, notes, and snippets.

@Nemo157
Created January 12, 2017 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nemo157/bf799fa23c25a667fd5e2f1677981f02 to your computer and use it in GitHub Desktop.
Save Nemo157/bf799fa23c25a667fd5e2f1677981f02 to your computer and use it in GitHub Desktop.

Examples

Basic example

catch {
    let decoded = bs58::decode("he11owor1d").into_vec()?;
    let encoded = bs58::encode(decoded).into_string();
    assert_eq!("he11owor1d", encoded);
}

Changing the alphabet

catch {
    let decoded = bs58::decode("he11owor1d")
        .with_alphabet(bs58::alphabet::RIPPLE)
        .into_vec()?;
    let encoded = bs58::encode(decoded)
        .with_alphabet(bs58::alphabet::FLICKR)
        .into_string();
    assert_eq!("4DSSNaN1SC", encoded);
}

Decoding into an existing buffer

catch {
    let (mut decoded, mut encoded) = ([0xFF; 8], String::with_capacity(10));
    bs58::decode("he11owor1d").into(&mut decoded)?;
    bs58::encode(decoded).into(&mut encoded);
    assert_eq!("he11owor1d", encoded);
}

Examples

Basic example

let decoded = bs58::decode("he11owor1d").into_vec()?;
let encoded = bs58::encode(decoded).into_string();
assert_eq!("he11owor1d", encoded);

Changing the alphabet

let decoded = bs58::decode("he11owor1d")
    .with_alphabet(bs58::alphabet::RIPPLE)
    .into_vec()?;
let encoded = bs58::encode(decoded)
    .with_alphabet(bs58::alphabet::FLICKR)
    .into_string();
assert_eq!("4DSSNaN1SC", encoded);

Decoding into an existing buffer

let (mut decoded, mut encoded) = ([0xFF; 8], String::with_capacity(10));
bs58::decode("he11owor1d").into(&mut decoded)?;
bs58::encode(decoded).into(&mut encoded);
assert_eq!("he11owor1d", encoded);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment