[−][src]Function rusty_ulid::crockford::parse_crockford_u64_tuple
pub fn parse_crockford_u64_tuple(
input: &str
) -> Result<(u64, u64), DecodingError>
Parses the given crockford Base32 string into a (u64, u64)
.
Examples
use rusty_ulid::crockford::*; let parsed = parse_crockford_u64_tuple("0000000000000000000000007Z"); assert_eq!(Ok((0, 0xFF)), parsed);
When decoding, upper and lower case letters are accepted,
i
and l
will be treated as 1
and o
will be treated as 0
.
use rusty_ulid::crockford::*; let parsed = parse_crockford_u64_tuple("00000000000000000x1iIlLoO0")?; let mut string_representation = String::new(); append_crockford_u64_tuple(parsed, &mut string_representation); assert_eq!(string_representation, "00000000000000000X11111000");
Errors
Parsing a string with other than 26 bytes results in InvalidLength
.
use rusty_ulid::crockford::*; let nope = parse_crockford_u64_tuple("1234567890123456789012345"); assert_eq!(Err(DecodingError::InvalidLength), nope);
use rusty_ulid::crockford::*; let nope = parse_crockford_u64_tuple("123456789012345678901234567"); assert_eq!(Err(DecodingError::InvalidLength), nope);
Parsing 26 bytes results in DataTypeOverflow
if the (u64, u64)
would overflow.
use rusty_ulid::crockford::*; let yeah = parse_crockford_u64_tuple("7ZZZZZZZZZZZZZZZZZZZZZZZZZ"); assert_eq!(Ok((0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), yeah); let nope = parse_crockford_u64_tuple("80000000000000000000000000"); assert_eq!(Err(DecodingError::DataTypeOverflow), nope);
Parsing a string containing an invalid character results in InvalidChar
containing
the character.
use rusty_ulid::crockford::*; let nope = parse_crockford_u64_tuple("0000000000000000000000000U"); assert_eq!(Err(DecodingError::InvalidChar('U')), nope);