Struct rusty_ulid::Ulid
[−]
[src]
pub struct Ulid(pub u64, pub u64);
The ULID data type.
Methods
impl Ulid
[src]
pub fn new() -> Ulid
[src]
Creates a new ULID.
Examples
let ulid = Ulid::new(); // ulid.0 contains the timestamp so it will never be 0. assert_ne!(0, ulid.0); let ulid_string = ulid.to_string(); // every ulid has exactly 26 characters assert_eq!(ulid_string.len(), 26);
Panics
Panics if called after +10889-08-02 05:31:50.655 UTC
.
pub fn from_timestamp_with_rng<R>(timestamp: u64, rng: &mut R) -> Ulid where
R: Rng,
[src]
R: Rng,
Creates a new ULID with the given timestamp
obtaining randomness from
rng
.
Examples
// TODO: works in nightly and beta but not in stable. wat? // https://users.rust-lang.org/t/i-have-a-strange-documentation-test-issue-related-to-extern-crate/16709 /* extern crate rand; let ulid = Ulid::from_timestamp_with_rng(0, &mut rand::thread_rng()); let timestamp = ulid.timestamp(); assert_eq!(timestamp, 0); */
Panics
Panics if timestamp
is larger than 0xFFFF_FFFF_FFFF
.
pub fn timestamp(&self) -> u64
[src]
Returns the timestamp of this ULID as number of non-leap milliseconds since January 1, 1970 0:00:00 UTC (aka "UNIX timestamp").
Examples
let ulid = Ulid::from_str("01CAH7NXGRDJNE9B1NY7PQGYV7"); let timestamp = ulid?.timestamp(); assert_eq!(timestamp, 1523144390168);
pub fn datetime(&self) -> DateTime<Utc>
[src]
Returns the timestamp of this ULID as a DateTime<Utc>
.
Examples
let ulid = Ulid::from_str("01CAH7NXGRDJNE9B1NY7PQGYV7"); let datetime = ulid?.datetime(); assert_eq!(datetime.to_string(), "2018-04-07 23:39:50.168 UTC");
pub fn to_string(&self) -> String
[src]
Returns the string representaton of this ULID.
Examples
let ulid = Ulid(0, 0); assert_eq!(ulid.to_string(), "00000000000000000000000000");
let ulid = Ulid(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); assert_eq!(ulid.to_string(), "7ZZZZZZZZZZZZZZZZZZZZZZZZZ");
Trait Implementations
impl Debug for Ulid
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Default for Ulid
[src]
impl PartialOrd for Ulid
[src]
fn partial_cmp(&self, __arg_0: &Ulid) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Ulid) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Ulid) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Ulid) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Ulid) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialEq for Ulid
[src]
fn eq(&self, __arg_0: &Ulid) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Ulid) -> bool
[src]
This method tests for !=
.
impl Copy for Ulid
[src]
impl Clone for Ulid
[src]
fn clone(&self) -> Ulid
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Display for Ulid
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl FromStr for Ulid
[src]
type Err = DecodingError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
Parses a string s
to return a value of this type. Read more
impl From<[u8; 16]> for Ulid
[src]
fn from(bytes: [u8; 16]) -> Self
[src]
Examples
let bytes: [u8; 16] = [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xF0, 0x0F, ]; let ulid = Ulid::from(bytes); let expected_ulid = Ulid(0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); assert_eq!(ulid, expected_ulid);
let bytes: [u8; 16] = [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xF0, 0x0F, ]; let ulid : Ulid = bytes.into(); let expected_ulid = Ulid(0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); assert_eq!(ulid, expected_ulid);
impl From<Ulid> for [u8; 16]
[src]
fn from(ulid: Ulid) -> Self
[src]
Examples
let ulid = Ulid(0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); let bytes = <[u8; 16]>::from(ulid); let expected_bytes: [u8; 16] = [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xF0, 0x0F, ]; assert_eq!(bytes, expected_bytes);
let ulid = Ulid(0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); let bytes: [u8; 16] = ulid.into(); let expected_bytes: [u8; 16] = [ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xF0, 0x0F, ]; assert_eq!(bytes, expected_bytes);
impl From<(u64, u64)> for Ulid
[src]
fn from(tuple: (u64, u64)) -> Self
[src]
Examples
let tuple = (0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); let ulid = Ulid::from(tuple); let expected_ulid = Ulid(0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); assert_eq!(ulid, expected_ulid);
let tuple = (0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); let ulid : Ulid = tuple.into(); let expected_ulid = Ulid(0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); assert_eq!(ulid, expected_ulid);
impl From<Ulid> for (u64, u64)
[src]
fn from(ulid: Ulid) -> Self
[src]
Examples
let ulid = Ulid(0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); let tuple = <(u64, u64)>::from(ulid); let expected_tuple = (0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); assert_eq!(tuple, expected_tuple);
let ulid = Ulid(0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); let tuple : (u64, u64) = ulid.into(); let expected_tuple = (0x1122_3344_5566_7788, 0x99AA_BBCC_DDEE_F00F); assert_eq!(tuple, expected_tuple);