Struct rusty_ulid::Ulid [] [src]

pub struct Ulid(pub u64, pub u64);

The ULID data type.

Methods

impl Ulid
[src]

[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.

[src]

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.

[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);

[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");

[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]

[src]

Formats the value using the given formatter. Read more

impl Default for Ulid
[src]

[src]

Returns the "default value" for a type. Read more

impl PartialOrd for Ulid
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[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]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Copy for Ulid
[src]

impl Clone for Ulid
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Display for Ulid
[src]

[src]

Formats the value using the given formatter. Read more

impl FromStr for Ulid
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

impl From<[u8; 16]> for Ulid
[src]

[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]

[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]

[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]

[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);

Auto Trait Implementations

impl Send for Ulid

impl Sync for Ulid