Struct oysterpack_uid::uid::Uid [−][src]
pub struct Uid<T: ?Sized> { /* fields omitted */ }
Represents a ULID for some type T.
By default, Uid is serializable via serde. If serialization is not needed then you can opt out by
including the dependency with default features disabled : default-features = false
.
Examples
Uid for structs
struct Domain; type DomainId = Uid<Domain>; let id = DomainId::new();
Uid for traits
trait Foo{} // traits are not Send. Send is added to the type def in order to satisfy Uid type constraints // in order to be able to send the Uid across threads type FooId = Uid<dyn Foo + Send + Sync>; let id = FooId::new();
Methods
impl<T: 'static + ?Sized> Uid<T>
[src]
impl<T: 'static + ?Sized> Uid<T>
pub fn new() -> Uid<T>
[src]
pub fn new() -> Uid<T>
New Uid instances are guaranteed to be lexographically sortable if they are created within the same millisecond. In other words, Uid(s) created within the same millisecond are random.
pub fn next(previous: Uid<T>) -> Option<Uid<T>>
[src]
pub fn next(previous: Uid<T>) -> Option<Uid<T>>
Creates the next strictly monotonic ULID for the given previous ULID. Returns None if the random part of the next ULID would overflow.
pub fn id(&self) -> u128
[src]
pub fn id(&self) -> u128
returns the id
pub fn datetime(&self) -> DateTime<Utc>
[src]
pub fn datetime(&self) -> DateTime<Utc>
Returns the timestamp of this ULID as a DateTime
pub fn increment(self) -> Option<Uid<T>>
[src]
pub fn increment(self) -> Option<Uid<T>>
Returns a new ULID with the random part incremented by one. Returns None if the new ULID overflows.
Trait Implementations
impl<T: 'static> Serialize for Uid<T>
[src]
impl<T: 'static> Serialize for Uid<T>
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
[src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de, T: 'static> Deserialize<'de> for Uid<T>
[src]
impl<'de, T: 'static> Deserialize<'de> for Uid<T>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<T: 'static + ?Sized> Display for Uid<T>
[src]
impl<T: 'static + ?Sized> Display for Uid<T>
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl<T: 'static + ?Sized> PartialEq for Uid<T>
[src]
impl<T: 'static + ?Sized> PartialEq for Uid<T>
fn eq(&self, other: &Uid<T>) -> bool
[src]
fn eq(&self, other: &Uid<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<T: 'static + ?Sized> PartialOrd for Uid<T>
[src]
impl<T: 'static + ?Sized> PartialOrd for Uid<T>
fn partial_cmp(&self, other: &Uid<T>) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Uid<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T: 'static + ?Sized> Eq for Uid<T>
[src]
impl<T: 'static + ?Sized> Eq for Uid<T>
impl<T: 'static + ?Sized> Ord for Uid<T>
[src]
impl<T: 'static + ?Sized> Ord for Uid<T>
fn cmp(&self, other: &Self) -> Ordering
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<T: 'static + ?Sized> Hash for Uid<T>
[src]
impl<T: 'static + ?Sized> Hash for Uid<T>
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T: 'static + ?Sized> Copy for Uid<T>
[src]
impl<T: 'static + ?Sized> Copy for Uid<T>
impl<T: 'static + ?Sized> Clone for Uid<T>
[src]
impl<T: 'static + ?Sized> Clone for Uid<T>
fn clone(&self) -> Uid<T>
[src]
fn clone(&self) -> Uid<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T: 'static + ?Sized> Debug for Uid<T>
[src]
impl<T: 'static + ?Sized> Debug for Uid<T>
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl<T: 'static + ?Sized> From<[u8; 16]> for Uid<T>
[src]
impl<T: 'static + ?Sized> From<[u8; 16]> for Uid<T>
impl<T: 'static + ?Sized> From<u128> for Uid<T>
[src]
impl<T: 'static + ?Sized> From<u128> for Uid<T>
impl<T: 'static + ?Sized> From<(u64, u64)> for Uid<T>
[src]
impl<T: 'static + ?Sized> From<(u64, u64)> for Uid<T>
impl<T: 'static + ?Sized> FromStr for Uid<T>
[src]
impl<T: 'static + ?Sized> FromStr for Uid<T>
type Err = DecodingError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses a string s
to return a value of this type. Read more
impl<T: 'static + ?Sized> From<Uid<T>> for u128
[src]
impl<T: 'static + ?Sized> From<Uid<T>> for u128
impl<T: 'static + ?Sized> From<Uid<T>> for (u64, u64)
[src]
impl<T: 'static + ?Sized> From<Uid<T>> for (u64, u64)