Ulid

Struct Ulid 

Source
pub struct Ulid;
Available on crate features 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

Source

pub fn new_ulid() -> ULID

Available on crate features 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();
Source

pub fn new_mono_ulid() -> ULID

Available on crate features 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();
Source

pub fn with_mono_backoff(strategy: Backoff) -> ULID

Available on crate features 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);
Source

pub fn from_timestamp(timestamp: <ULID as Id>::Ty) -> ULID

Available on crate features 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);
Source

pub fn from_timestamp_and_rand<R>(timestamp: <ULID as Id>::Ty, rng: &R) -> ULID
where R: RandSource<<ULID as Id>::Ty>,

Available on crate features 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);
Source

pub fn from_datetime(datetime: SystemTime) -> ULID

Available on crate features 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());
Source

pub fn from_datetime_and_rand<R>(datetime: SystemTime, rng: &R) -> ULID
where R: RandSource<<ULID as Id>::Ty>,

Available on crate features 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);

Auto Trait Implementations§

§

impl Freeze for Ulid

§

impl RefUnwindSafe for Ulid

§

impl Send for Ulid

§

impl Sync for Ulid

§

impl Unpin for Ulid

§

impl UnwindSafe for Ulid

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V