#base64 #byte-array #base32 #identifier #uuid #ids


Base32 and base64 encoding in Rust. Primarily for integer (u64, u128) and UUID identifiers, as well as arbitrary byte arrays.

3 stable releases

1.0.2 Dec 27, 2023
1.0.1 Dec 12, 2023
1.0.0 Dec 11, 2023

#838 in Encoding

Download history 307/week @ 2024-01-20 744/week @ 2024-01-27 209/week @ 2024-02-03 396/week @ 2024-02-10 291/week @ 2024-02-17 190/week @ 2024-02-24 88/week @ 2024-03-02 239/week @ 2024-03-09 146/week @ 2024-03-16 288/week @ 2024-03-23 201/week @ 2024-03-30 265/week @ 2024-04-06 130/week @ 2024-04-13 68/week @ 2024-04-20 332/week @ 2024-04-27 146/week @ 2024-05-04

707 downloads per month
Used in 2 crates (via package-family-name)

MIT license

3.5K SLoC


Base32 and base64 encoding in Rust. Primarily for integer (u64, u128) and UUID identifiers (behind feature uuid), as well as arbitrary byte arrays. And do it all very quickly (more on this below).

The crate has installation instructions, and the documentation has extensive examples.

Encoding integers

Note that by default, encoding an integer into base32 or base64 via normal algorithms does not "look like" a number -- notably the rightmost character usually looks off, and there are sometimes more characters than there needs to be. This might be a plus for obfuscation, barely, but it makes them hard to reason about quickly, and it's also more efficient to process them as integers rather than arbitrary arrays of bytes (because we know upfront that integers are always a small size).

For example, the normal/base10 integer 31 processed normally, as bytes, into official RFC 4648 base32 hex, without padding, will come out as "D4". In contrast, processing it as an integer, as this library can, will come out as "Z" (in Crockford's base32 alphabet) which is more intuitively one less than 32 at "10", as one might hope (vs "EA" in base32 hex -- note that's an A not a 4 so the string changed nonintuitively for an increment of 1). This is helpful with "nice looking" urls of base32 encodings of identifiers, etc.


This is intended to be as fast as basically possible, while still keeping an intuitive interface.

It is, per the bench comparisons in this repo, on my machine, about 65-100%+ faster than the closest alternative for decoding u64s, and ~15-50%+ faster for encoding u64s, with bigger percent improvements for larger numbers. (That repo does not offer u128 or uuid support to compare against.)

It is also ~35-40% faster on decoding and encoding raw bytes vs the closest other alternative that is more mature but does not offer this crate's integer encoding/decoding, on top of the slower performance. There is an earlier and seemingly long abandoned alternative that is generally about 3x slower than this crate (and thus ~2x slower than the other alternative as well), but still somewhat popular.


In short, this crate should do everything you want for base32 and base64 encoding (please raise an issue if it doesn't!) while doing all of it very quickly and conveniently.