[−][src]Struct ulid::Ulid
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.
Methods
impl Ulid
[src]
pub fn new() -> Ulid
[src]
pub fn with_source<R: Rng>(source: &mut R) -> Ulid
[src]
Creates a new Ulid using data from the given random number generator
Example
use rand::FromEntropy; use rand::rngs::SmallRng; use ulid::Ulid; let mut rng = SmallRng::from_entropy(); let ulid = Ulid::with_source(&mut rng);
pub fn from_datetime<T: TimeZone>(datetime: DateTime<T>) -> Ulid
[src]
Creates a new Ulid with the given datetime
This can be useful when migrating data to use Ulid identifiers
Example
use chrono::offset::Utc; use ulid::Ulid; let ulid = Ulid::from_datetime(Utc::now());
pub fn from_datetime_with_source<T, R>(
datetime: DateTime<T>,
source: &mut R
) -> Ulid where
T: TimeZone,
R: Rng,
[src]
datetime: DateTime<T>,
source: &mut R
) -> Ulid where
T: TimeZone,
R: Rng,
Creates a new Ulid with the given datetime and random number generator
Example
use chrono::offset::Utc; use rand::FromEntropy; use rand::rngs::SmallRng; use ulid::Ulid; let mut rng = SmallRng::from_entropy(); let ulid = Ulid::from_datetime_with_source(Utc::now(), &mut rng);
pub fn from_string(encoded: &str) -> Result<Ulid, EncodingError>
[src]
Creates a Ulid from a Crockford Base32 encoded string
An EncodingError will be returned when the given string is not formated properly.
Example
use ulid::Ulid; let text = "01D39ZY06FGSCTVN4T2V9PKHFZ"; let result = Ulid::from_string(text); assert!(result.is_ok()); assert_eq!(&result.unwrap().to_string(), text);
pub fn nil() -> Ulid
[src]
The 'nil Ulid'.
The nil Ulid is special form of Ulid that is specified to have all 128 bits set to zero.
Example
use ulid::Ulid; let ulid = Ulid::nil(); assert_eq!( ulid.to_string(), "00000000000000000000000000" );
pub fn datetime(&self) -> DateTime<Utc>
[src]
Gets the datetime of when this Ulid was created accurate to 1ms
Example
use chrono::Duration; use chrono::offset::Utc; use ulid::Ulid; let dt = Utc::now(); let ulid = Ulid::from_datetime(dt); assert!((dt - ulid.datetime()) < Duration::milliseconds(1));
pub fn timestamp_ms(&self) -> u64
[src]
Gets the timestamp section of this ulid
Example
use chrono::offset::Utc; use ulid::Ulid; let dt = Utc::now(); let ulid = Ulid::from_datetime(dt); assert_eq!(ulid.timestamp_ms(), dt.timestamp_millis() as u64);
pub fn to_string(&self) -> String
[src]
Creates a Crockford Base32 encoded string that represents this Ulid
Example
use ulid::Ulid; let text = "01D39ZY06FGSCTVN4T2V9PKHFZ"; let ulid = Ulid::from_string(text).unwrap(); assert_eq!(&ulid.to_string(), text);
pub fn is_nil(&self) -> bool
[src]
Test if the Ulid is nil
Example
use ulid::Ulid; let ulid = Ulid::new(); assert!(!ulid.is_nil()); let nil = Ulid::nil(); assert!(nil.is_nil());
Trait Implementations
impl<'a> Into<String> for &'a Ulid
[src]
impl Into<(u64, u64)> for Ulid
[src]
impl Into<u128> for Ulid
[src]
impl From<(u64, u64)> for Ulid
[src]
impl From<u128> for Ulid
[src]
impl Default for Ulid
[src]
impl PartialEq<Ulid> for Ulid
[src]
impl PartialOrd<Ulid> for Ulid
[src]
fn partial_cmp(&self, other: &Ulid) -> Option<Ordering>
[src]
fn lt(&self, other: &Ulid) -> bool
[src]
fn le(&self, other: &Ulid) -> bool
[src]
fn gt(&self, other: &Ulid) -> bool
[src]
fn ge(&self, other: &Ulid) -> bool
[src]
impl Eq for Ulid
[src]
impl Copy for Ulid
[src]
impl Ord for Ulid
[src]
fn cmp(&self, other: &Ulid) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl Clone for Ulid
[src]
fn clone(&self) -> Ulid
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Ulid
[src]
impl Display for Ulid
[src]
impl Hash for Ulid
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl FromStr for Ulid
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,