Expand description
High-performance unique ID generators for low-latency systems.
§Overview
nexus-id provides unique ID generation optimized for trading systems and
other latency-sensitive applications. All generators avoid syscalls on the
hot path and produce stack-allocated output.
| Generator | Speed (p50) | Time-ordered | Output | Use Case |
|---|---|---|---|---|
Snowflake64 | ~22 cycles | Yes | SnowflakeId64 | Numeric IDs with extraction |
Snowflake32 | ~22 cycles | Yes | SnowflakeId32 | Compact numeric IDs |
UuidV4 | ~48 cycles | No | Uuid | Random unique IDs |
UuidV7 | ~62 cycles | Yes | Uuid | Time-ordered UUIDs |
UlidGenerator | ~80 cycles | Yes | Ulid | Sortable 26-char IDs |
§ID Types
| Type | Format | Use Case |
|---|---|---|
SnowflakeId64 | Packed u64 | Numeric IDs with field extraction |
MixedId64 | Fibonacci-mixed u64 | Identity hasher-safe keys |
Uuid | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | Standard UUIDs |
UuidCompact | 32-char hex | Compact UUIDs |
Ulid | 26-char Crockford Base32 | Sortable string IDs |
HexId64 | 16-char hex | Hex-encoded u64 |
Base62Id | 11-char alphanumeric | Short encoded u64 |
Base36Id | 13-char alphanumeric | Case-insensitive u64 |
TypeId | prefix_suffix | Domain-typed sortable IDs |
§Parsing
All string types support parsing from strings:
use nexus_id::{Uuid, Ulid, HexId64};
let uuid: Uuid = "01234567-89ab-cdef-fedc-ba9876543210".parse().unwrap();
let hex: HexId64 = "deadbeefcafebabe".parse().unwrap();§Snowflake ID Newtypes
use nexus_id::{Snowflake64, SnowflakeId64, MixedId64};
let mut generator: Snowflake64<42, 6, 16> = Snowflake64::new(5);
// Typed ID with field extraction
let id: SnowflakeId64<42, 6, 16> = generator.next_id(0).unwrap();
assert_eq!(id.worker(), 5);
assert_eq!(id.sequence(), 0);
// Mixed for identity hashers (Fibonacci multiply, ~1 cycle)
let mixed: MixedId64<42, 6, 16> = id.mixed();
let recovered = mixed.unmix();
assert_eq!(recovered, id);§HashMap Usage
Snowflake IDs have poor bit distribution for power-of-2 hash tables. Use either a real hasher or the mixed ID type:
ⓘ
use rustc_hash::FxHashMap;
// Option 1: Use a real hasher with raw IDs
let map: FxHashMap<SnowflakeId64<42, 6, 16>, Order> = FxHashMap::default();
// Option 2: Use mixed IDs with identity hasher (fastest)
let map: HashMap<MixedId64<42, 6, 16>, Order, nohash::BuildNoHashHasher<u64>> = ...;§Features
Re-exports§
pub use ulid::UlidGenerator;pub use uuid::UuidV4;pub use uuid::UuidV7;
Modules§
- ulid
- ULID generator (Universally Unique Lexicographically Sortable Identifier).
- uuid
- UUID generators optimized for high-performance systems.
Structs§
- Base36
Id - Base36-encoded 64-bit ID.
- Base62
Id - Base62-encoded 64-bit ID.
- HexId64
- Hex-encoded 64-bit ID.
- Mixed
Id32 - 32-bit Snowflake ID with Fibonacci-mixed bits.
- Mixed
Id64 - 64-bit Snowflake ID with Fibonacci-mixed bits.
- Sequence
Exhausted - Sequence exhausted within the current tick.
- Snowflake
- Snowflake ID generator.
- Snowflake
Id32 - 32-bit Snowflake ID with compile-time layout.
- Snowflake
Id64 - 64-bit Snowflake ID with compile-time layout.
- TypeId
- Type-prefixed sortable identifier.
- Ulid
- ULID (Universally Unique Lexicographically Sortable Identifier).
- Uuid
- UUID in standard dashed format.
- Uuid
Compact - UUID in compact format (no dashes).
Enums§
- Decode
Error - Error parsing a base-N encoded ID string.
- Parse
Error - Error parsing a fixed-format ID string.
- Type
IdParse Error - Error parsing or constructing a TypeId.
- Uuid
Parse Error - Error parsing a UUID string.
Traits§
- IdInt
- Integer types usable as snowflake IDs.
Type Aliases§
- Snowflake32
- 32-bit snowflake generator.
- Snowflake64
- 64-bit snowflake generator.
- Snowflake
Signed32 - Signed 32-bit snowflake generator.
- Snowflake
Signed64 - Signed 64-bit snowflake generator.