Skip to main content

Module ulid

Module ulid 

Source
Available on crate feature ulid only.
Expand description

§ULID generation

Universally Unique Lexicographically Sortable Identifier per the ULID spec: 128 bits split as a 48-bit big-endian millisecond timestamp followed by 80 bits of randomness. Encoded as 26 Crockford base32 characters that sort byte-wise in creation order.

use id_forge::ulid::Ulid;

let a = Ulid::new();
let b = Ulid::new();
assert_eq!(a.to_string().len(), 26);
assert!(b > a);                                  // monotonic per process
let parsed = Ulid::parse_str(&a.to_string()).unwrap();
assert_eq!(a, parsed);

§Monotonicity

Within a single process, two ULIDs generated in the same millisecond are guaranteed to be byte-wise ordered: the second one is the first one’s 80-bit random suffix plus one. Across milliseconds, fresh randomness is drawn. This matches the “monotonic factory” guarantee in the spec.

§Randomness

The 80-bit random suffix comes from the shared inline xoshiro256** generator. It is fast and statistically strong but not cryptographically secure.

Structs§

Ulid
A 128-bit ULID.

Enums§

ParseError
Error returned by Ulid::parse_str.