mr-ulid
A Rust implementation of ULIDs (Universally Unique Lexicographically Sortable Identifiers) with a focus on correctness and ease of use.
Generated ULIDs are guaranteed to be unique and strictly monotonically increasing, even across threads. The random component is overflow-proof by design -- see Overflow Protection for details.
Usage
[]
= "3"
use Ulid;
let u = new;
println!;
let s = u.to_string;
let parsed: Ulid = s.parse.unwrap;
assert_eq!;
Features
- Overflow-proof generation -- At least 1010 ULIDs per millisecond without overflow or failure.
- Strict monotonicity -- Thread-safe generation; every ULID is greater than the previous one.
- Non-zero type (
Ulid) -- WrapsNonZero<u128>, soOption<Ulid>is the same size asUlid(16 bytes). - Zeroable type (
ZeroableUlid) -- For use cases that need a zero sentinel value. - Crockford Base32 -- Case-insensitive encoding with automatic
i/lto1andoto0disambiguation. - Optional
serdesupport -- Enable theserdefeature for string-based serialization. - Custom entropy sources -- Swap in your own RNG via the
EntropySourcetrait. - Minimal dependencies -- Only
rand(enabled by default). Disable withdefault-features = false.
Serde
Enable the serde feature for JSON (and other format) support:
[]
= { = "3", = ["serde"] }
use Ulid;
use ;
ULIDs are serialized as 26-character Crockford Base32 strings.
Overflow Protection
The 80-bit random component is reduced by 1010 values (a ~0.000000000001% reduction in entropy). This reserves enough space to guarantee at least 1010 monotonically increasing ULIDs per millisecond -- equivalent to 1013 per second -- without overflow or failure. This exceeds the capability of current hardware by orders of magnitude.
Changelog
See CHANGELOG.md for version history.