Crate typedflake

Crate typedflake 

Source
Expand description

§TypedFlake

Distributed, type-safe Snowflake ID generation for Rust.

Generate unique, time-ordered 64-bit IDs across distributed systems without coordination. Each ID type is a distinct newtype that cannot be mixed with others at compile time.

§Quick Start

typedflake::id!(UserId);

fn example() {
    let id = UserId::generate();
    let (timestamp, worker_id, process_id, sequence) = id.decompose();
}

§Main Types

  • Config - Complete configuration (bit layout + epoch)
  • BitLayout - Bit allocation for the 64-bit ID space
  • Epoch - Custom epoch timestamps

Use the id! macro to create new ID types with their own independent state.

Re-exports§

pub use config::BitLayout;
pub use config::BitLayoutError;
pub use config::Config;
pub use config::ConfigError;
pub use config::Epoch;
pub use config::EpochError;
pub use config::ValidationError;
pub use context::IdContext;
pub use generator::Generator;
pub use generator::GeneratorError;
pub use generator::IdComponents;

Modules§

config
Configuration types for ID generation.
context
Per-type ID context and generator factory.
generator
Core ID generation and component manipulation.
global
Global default configuration and instance management.
state
Atomic state management and lazy state pooling.

Macros§

id
Generate a type-safe ID newtype.