pub struct Ulid;ulid and thread-local only.Expand description
A thread-local ULID generator with monotonic and non-monotonic modes.
Provides fast, per-thread ULID generation using a shared monotonic clock and
thread-local RNG. Monotonic overflows are handled with configurable
Backoff strategies.
Implementations§
Source§impl Ulid
impl Ulid
Sourcepub fn new_ulid() -> ULID
Available on crate features snowflake or ulid only.
pub fn new_ulid() -> ULID
snowflake or ulid only.Generates a non-monotonic ULID that is always random, even when generated within the same millisecond.
§Example
use ferroid::Ulid;
let id = Ulid::new_ulid();Sourcepub fn new_mono_ulid() -> ULID
Available on crate features snowflake or ulid only.
pub fn new_mono_ulid() -> ULID
snowflake or ulid only.Generates a monotonic ULID using Backoff::Yield as the overflow
strategy.
§Example
use ferroid::Ulid;
let id = Ulid::new_mono_ulid();Sourcepub fn with_mono_backoff(strategy: Backoff) -> ULID
Available on crate features snowflake or ulid only.
pub fn with_mono_backoff(strategy: Backoff) -> ULID
snowflake or ulid only.Generates a monotonic ULID using the given Backoff strategy to
handle overflow.
If the generator exhausts available entropy within the same millisecond, the backoff strategy determines how it waits before retrying.
§Example
use ferroid::{Ulid, Backoff};
let id = Ulid::with_mono_backoff(Backoff::Spin);Sourcepub fn from_timestamp(timestamp: <ULID as Id>::Ty) -> ULID
Available on crate features snowflake or ulid only.
pub fn from_timestamp(timestamp: <ULID as Id>::Ty) -> ULID
snowflake or ulid only.Creates a ULID from a given millisecond timestamp.
Random bits are generated using the thread-local RNG. The resulting ID is not guaranteed to be monotonic.
§Example
use ferroid::Ulid;
let id = Ulid::from_timestamp(1_694_201_234_000);Sourcepub fn from_timestamp_and_rand<R>(timestamp: <ULID as Id>::Ty, rng: &R) -> ULID
Available on crate features snowflake or ulid only.
pub fn from_timestamp_and_rand<R>(timestamp: <ULID as Id>::Ty, rng: &R) -> ULID
snowflake or ulid only.Creates a ULID from a given millisecond timestamp and a custom RNG.
Useful in deterministic or testable scenarios where a specific random source is preferred.
§Example
use ferroid::{Ulid, ThreadRandom};
let id = Ulid::from_timestamp_and_rand(0, &ThreadRandom);Sourcepub fn from_datetime(datetime: SystemTime) -> ULID
Available on crate features snowflake or ulid only.
pub fn from_datetime(datetime: SystemTime) -> ULID
snowflake or ulid only.Creates a ULID from a SystemTime.
This is a convenience wrapper over Ulid::from_timestamp that
extracts the Unix timestamp in milliseconds.
§Example
use ferroid::Ulid;
let id = Ulid::from_datetime(std::time::SystemTime::now());Sourcepub fn from_datetime_and_rand<R>(datetime: SystemTime, rng: &R) -> ULID
Available on crate features snowflake or ulid only.
pub fn from_datetime_and_rand<R>(datetime: SystemTime, rng: &R) -> ULID
snowflake or ulid only.Creates a ULID from a SystemTime and a custom RNG.
§Example
use ferroid::{Ulid, ThreadRandom};
let now = std::time::SystemTime::now();
let id = Ulid::from_datetime_and_rand(now, &ThreadRandom);