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]
fn new(timestamp: u32, payload: [u8; 16]) -> Self
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]);
fn with_payload(payload: [u8; 16]) -> Self
Create a new identifier with a current timestamp and the given payload.
fn generate() -> Self
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.
fn from_base62(s: &str) -> Result<Self>
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);
fn from_hex(hex: &str) -> Result<Self>
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);
fn from_bytes(raw: &[u8]) -> Result<Self>
Parse an identifier from its binary representation.
raw
must be exactly 20 bytes long.
fn to_base62(&self) -> String
The Base62-encoded version of this identifier.
Examples
let id = ksuid::Ksuid::new(::std::u32::MAX, [255; 16]); assert_eq!(id.to_base62(), "aWgEPTl1tmebfsQzFP4bxwgy80V");
fn to_hex(&self) -> String
The hex-encoded version of this identifier.
fn as_bytes(&self) -> &[u8]
The 20-byte binary representation of this identifier.
fn timestamp(&self) -> u32
The 32-bit timestamp of this identifier.
Most consumers should use Ksuid::time()
to extract
the creation date of an identifer.
fn set_timestamp(&mut self, timestamp: u32)
Set the 32-bit timestamp.
fn time(&self) -> Timespec
The number of seconds after the UNIX epoch when this identifier was created.
fn set_time(&mut self, time: Timespec)
Set the timestamp of the identifier to the given time.
fn payload(&self) -> &[u8]
The 16-byte random payload.
fn set_payload(&mut self, payload: [u8; 16])
Set the 16-byte payload.
Trait Implementations
impl Clone for Ksuid
[src]
fn clone(&self) -> Ksuid
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Copy for Ksuid
[src]
impl Ord for Ksuid
[src]
fn cmp(&self, __arg_0: &Ksuid) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl PartialOrd for Ksuid
[src]
fn partial_cmp(&self, __arg_0: &Ksuid) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Ksuid) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Ksuid) -> bool
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: &Ksuid) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Ksuid) -> bool
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]
fn eq(&self, __arg_0: &Ksuid) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Ksuid) -> bool
This method tests for !=
.