Expand description
SCRU64: Sortable, Clock-based, Realm-specifically Unique identifier
SCRU64 ID offers compact, time-ordered unique identifiers generated by distributed nodes. SCRU64 has the following features:
- ~62-bit non-negative integer storable as signed/unsigned 64-bit integer
- Sortable by generation time (as integer and as text)
- 12-digit case-insensitive textual representation (Base36)
- ~38-bit Unix epoch-based timestamp that ensures useful life until year 4261
- Variable-length node/machine ID and counter fields that share 24 bits
// pass node ID through environment variable
std::env::set_var("SCRU64_NODE_SPEC", "42/8");
// generate a new identifier object
let x = scru64::new();
println!("{}", x); // e.g., "0u2r85hm2pt3"
println!("{}", x.to_u64()); // as a 64-bit unsigned integer
// generate a textual representation directly
println!("{}", scru64::new_string()); // e.g., "0u2r85hm2pt4"See SCRU64 Specification for details.
SCRU64’s uniqueness is realm-specific, i.e., dependent on the centralized assignment of node ID to each generator. If you need decentralized, globally unique time-ordered identifiers, consider SCRU128.
Crate features
Default features:
stdintegrates the library with, among others, the system clock to draw current timestamps. Withoutstd, this crate provides limited functionality available underno_stdenvironments.global_gen(impliesstd) enables the primarynew()andnew_string()functions and the process-wide global generator under the hood.
Optional features:
serdeenables serialization/deserialization via serde.tokio(together withglobal_gen) enables theasync_tokio::new()andasync_tokio::new_string()functions, the non-blocking counterpart ofnew()andnew_string().
Modules
- async_tokio
global_genandtokioNon-blocking global generator functions usingtokio. - SCRU64 generator and related items.
Structs
- An error parsing an invalid string representation of SCRU64 ID.
- An error passing invalid arguments to
Scru64Id::from_parts(). - An error converting an integer into a SCRU64 ID.
- Represents a SCRU64 ID.
Functions
- new
global_genGenerates a new SCRU64 ID object using the global generator. - new_string
global_genGenerates a new SCRU64 ID encoded in the 12-digit canonical string representation using the global generator.