[][src]Crate base62num

A convertor between usize and String in Base62.

Examples

use base62num::{encode, decode, Base62Error};

// It can convert an usize number into a string in Base62.
assert_eq!(encode(123), "B9");

// Vice versa.
assert_eq!(decode("B9"), Ok(123));

// Any non-alphanumeric character in the string is invalid.
assert_eq!(decode("Base*62"), Err(Base62Error::NonAlphanumeric));

// The conversion also failed if the result number is overflow.
assert_eq!(
    decode("AStringTooLongCausesTheOverflowError"),
    Err(Base62Error::Overflow)
);

Enums

Base62Error

Conversion errors between numbers and strings in Base62.

Functions

decode

Converts a string in Base62 into an number.

encode

Converts a number into a string in Base62.