1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::prelude::*;

pub use ulid::Ulid;

/// Extension trait for [`Ulid`].
pub trait UlidExt {
    /// Constructor that) is the same as [`Ulid::new()`], but that works on WASM, too using the
    /// [`instant`] crate.
    fn create() -> Self;
}

impl UlidExt for Ulid {
    fn create() -> Self {
        Ulid::from_parts(
            instant::now().floor() as u64,
            THREAD_RNG.with(|rng| rng.gen_u128()),
        )
    }
}