Struct oysterpack_uid::ulid::TypedULID
source · pub struct TypedULID<T: 'static + ?Sized> { /* private fields */ }
Expand description
A TypedULID represents a domain specific ULID, where the domain is defined and enforced by the type system.
How to define a TypedULID for structs
struct Foo;
type FooId = TypedULID<Foo>;
let id = FooId::generate();
How to define TypedULID for traits
trait Foo{}
// traits are not Send. Send is added to the type def in order to satisfy TypedULID type constraints
// in order to be able to send the TypedULID across threads
type FooId = TypedULID<dyn Foo + Send + Sync>;
let id = FooId::generate();
TypedULID<T> can be converted to a DomainULID automatically if the TypedULID type T implements HasDomain.
struct Foo;
impl HasDomain for Foo {
const DOMAIN: Domain = Domain("Foo");
}
type FooId = TypedULID<Foo>;
let id = FooId::generate();
let id: DomainULID = id.into();
assert_eq!(id.domain(), Foo::DOMAIN.name());
Implementations§
source§impl<T: 'static + ?Sized> TypedULID<T>
impl<T: 'static + ?Sized> TypedULID<T>
sourcepub fn generate() -> TypedULID<T>
pub fn generate() -> TypedULID<T>
New TypedULID instances are guaranteed to be lexographically sortable if they are created within the same millisecond. In other words, TypedULID(s) created within the same millisecond are random.
Trait Implementations§
source§impl<'de, T: 'static> Deserialize<'de> for TypedULID<T>
impl<'de, T: 'static> Deserialize<'de> for TypedULID<T>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: 'static + ?Sized> Ord for TypedULID<T>
impl<T: 'static + ?Sized> Ord for TypedULID<T>
source§impl<T: 'static + ?Sized> PartialEq<TypedULID<T>> for TypedULID<T>
impl<T: 'static + ?Sized> PartialEq<TypedULID<T>> for TypedULID<T>
source§impl<T: 'static + ?Sized> PartialOrd<TypedULID<T>> for TypedULID<T>
impl<T: 'static + ?Sized> PartialOrd<TypedULID<T>> for TypedULID<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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