This library is intended to provide an easy way to encode and decode identifiers (large integers) as Crockford-encoded strings. If you want to encode or decode arbitrary data, another library is probably a better choice.
Use the encode function to encode
u64 values into Crockford Base32-encoded strings. This
operation cannot fail, so you will always get back a string rather than any kind of result
let x = crockford::encode(5111); assert_eq!("4ZQ", &*x);
Because this is Rust, particular focus is given to runtime efficiency--or, at least, allowing the user to achieve runtime efficiency. As a result, we provide a second, more complicated encoding option.
// The longest possible representation of u64 is 13 digits. let mut buf = Vec::with_capacity(13); crockford::encode_into(5111, &mut buf); let result = std::str::from_utf8(&buf)?; assert_eq!("4ZQ", result);
encode_into method also accepts
&mut String, if you prefer.
Use the decode function to decode Crockford Base32-encoded strings. This operation can fail; if it does, you'll get a reasonably useful error instead of a number.
let x = crockford::decode("4zq"); let y = crockford::decode("4ZQ"); assert_eq!(5111, x?); assert_eq!(5111, y?);
Represents an error in decoding.
Represents writable buffer capable of receiving encoded data.
Attempts to decode a Crockford Base32-encoded string into a