pub struct Ulid(pub u128);
Expand description
A Ulid is a unique 128-bit lexicographically sortable identifier
Canonically, it is represented as a 26 character Crockford Base32 encoded string.
Of the 128-bits, the first 48 are a unix timestamp in milliseconds. The remaining 80 are random. The first 48 provide for lexicographic sorting and the remaining 80 ensure that the identifier is unique.
Tuple Fields§
§0: u128
Implementations§
source§impl Ulid
impl Ulid
sourcepub fn with_source<R: Rng>(source: &mut R) -> Ulid
pub fn with_source<R: Rng>(source: &mut R) -> Ulid
Creates a new Ulid using data from the given random number generator
sourcepub fn from_datetime<T: TimeZone>(datetime: DateTime<T>) -> Ulid
pub fn from_datetime<T: TimeZone>(datetime: DateTime<T>) -> Ulid
Creates a new Ulid with the given datetime
This can be useful when migrating data to use Ulid identifiers
sourcepub fn from_datetime_with_source<T, R>(
datetime: DateTime<T>,
source: &mut R
) -> Ulidwhere
T: TimeZone,
R: Rng,
pub fn from_datetime_with_source<T, R>(
datetime: DateTime<T>,
source: &mut R
) -> Ulidwhere
T: TimeZone,
R: Rng,
Creates a new Ulid with the given datetime and random number generator
sourcepub fn from_string(encoded: &str) -> Result<Ulid, EncodingError>
pub fn from_string(encoded: &str) -> Result<Ulid, EncodingError>
Creates a Ulid from a Crockford Base32 encoded string
An EncodingError will be returned when the given string is not formated properly.
sourcepub fn datetime(&self) -> DateTime<Utc>
pub fn datetime(&self) -> DateTime<Utc>
Gets the datetime of when this Ulid was created accurate to 1ms
sourcepub fn timestamp_ms(&self) -> u64
pub fn timestamp_ms(&self) -> u64
Gets the timestamp section of this ulid
Trait Implementations§
source§impl PartialOrd<Ulid> for Ulid
impl PartialOrd<Ulid> for Ulid
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more