Struct ksuid::Ksuid [] [src]

pub struct Ksuid(_);

A K-Sortable Unique IDentifier.

The first 4 bytes are a big-endian encoded, unsigned timestamp indicating when the UUID was created. The timestamp is relative to a custom epoch, exported from this crate as EPOCH.

The remaining 16 bytes is the randomly generated payload.

Methods

impl Ksuid
[src]

Create a new identifier with the given timestamp and payload.

Examples

let id = ksuid::Ksuid::new(1000, [0; 16]);
assert_eq!(id.timestamp(), 1000);
assert_eq!(id.payload(), [0; 16]);

Create a new identifier with a current timestamp and the given payload.

Create a new identifier with a current timestamp and randomly generated payload.

This function uses the thread local random number generator. this means that if you're calling generate() in a loop, caching the generator can increase performance. See the documentation of rand::random() for an example.

Parse an identifier from its Base62-encoded string representation.

s must be exactly 27 characters long.

Examples

let id = ksuid::Ksuid::from_base62("0o5Fs0EELR0fUjHjbCnEtdUwQe3").unwrap();
assert_eq!(id.timestamp(), 94985761);

Parse an identifer from a string of hex characters (/[0-9A-Fa-f]/).

hex must be exactly 40 characters long.

Examples

let id = ksuid::Ksuid::from_hex("05a95e21D7B6Fe8CD7Cff211704d8E7B9421210B").unwrap();
assert_eq!(id.timestamp(), 94985761);

Parse an identifier from its binary representation.

raw must be exactly 20 bytes long.

The Base62-encoded version of this identifier.

Examples

let id = ksuid::Ksuid::new(::std::u32::MAX, [255; 16]);
assert_eq!(id.to_base62(), "aWgEPTl1tmebfsQzFP4bxwgy80V");

The hex-encoded version of this identifier.

The 20-byte binary representation of this identifier.

The 32-bit timestamp of this identifier.

Most consumers should use Ksuid::time() to extract the creation date of an identifer.

Set the 32-bit timestamp.

The number of seconds after the UNIX epoch when this identifier was created.

Set the timestamp of the identifier to the given time.

The 16-byte random payload.

Set the 16-byte payload.

Trait Implementations

impl Clone for Ksuid
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Copy for Ksuid
[src]

impl Ord for Ksuid
[src]

This method returns an Ordering between self and other. Read more

impl PartialOrd for Ksuid
[src]

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

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

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

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

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

impl Eq for Ksuid
[src]

impl PartialEq for Ksuid
[src]

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

This method tests for !=.

impl Rand for Ksuid
[src]

Generates a random instance of this type using the specified source of randomness. Read more