Skip to main content

Crate obzenflow_idkit

Crate obzenflow_idkit 

Source
Expand description

Phantom-typed ULID identifiers.

Id<K> is a zero-cost wrapper around Ulid with a phantom kind K, preventing accidental mixing of IDs across domains.

By default this crate is type-only (no RNG dependencies). Enable the gen feature in application crates to generate IDs, and configure the RNG backend per target (for browser wasm, enable getrandom’s js feature in the app crate).

Define marker types (struct User; type UserId = Id<User>;) in your domain crates; this crate stays generic.

§Example

use obzenflow_idkit::{Id, Ulid};

struct User;
struct Order;

type UserId = Id<User>;
type OrderId = Id<Order>;

let _user_id = UserId::from_ulid(Ulid::from_string("01ARZ3NDEKTSV4RRFFQ69G5FAV").unwrap());
let _order_id = OrderId::from_ulid(Ulid::from_string("01ARZ3NDEKTSV4RRFFQ69G5FAW").unwrap());

// These are different types (won't compile):
// let mixed: UserId = _order_id;

// With `gen` enabled in an app crate:
// let generated = UserId::new();

Structs§

Id
A phantom-typed ID wrapper that provides type safety across domains.
Ulid
A Ulid is a unique 128-bit lexicographically sortable identifier