Struct uid::Id [−][src]
#[repr(transparent)]pub struct Id<T> { /* fields omitted */ }
Expand description
A struct representing IDs usable for various purposes.
Except for Debug
and Display
which are implemented
unconditionally, the type will only implement Clone
,
Copy
, Eq
, Ord
, PartialEq
, PartialOrd
, and
Hash
if the provided T
implements them.
Examples
A commonly seen pattern for creating of a type Id
that is unique
may look as follows:
use uid::Id as IdT;
#[derive(Copy, Clone, Eq, PartialEq)]
struct T(());
type Id = IdT<T>;
let id1 = Id::new();
let id2 = Id::new();
assert_ne!(id1, id2)
In this example the type T
is just an arbitrary type, but it
allows us to create distinct ID types. For example, when another ID
type is required for a different purpose, that can be easily
created:
#[derive(Copy, Clone)]
struct U(());
type Key = IdT<U>;
// `Key` and `Id` are fundamentally different types, with no
// allowed interaction between each other. That is, Rust's type
// system will prevent accidental usage of one in place of the
// other. The same can be said about the relationship to built-in
// numeric types such as `usize` or `u64`.
Implementations
Create a new unique ID.
Panics
This constructor panics if an overflow of the underlying counter occurred.
Trait Implementations
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