pub struct Id<T> { /* private fields */ }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§
Trait Implementations§
Source§impl<T: Ord> Ord for Id<T>
impl<T: Ord> Ord for Id<T>
Source§impl<T: PartialOrd> PartialOrd for Id<T>
impl<T: PartialOrd> PartialOrd for Id<T>
impl<T: Copy> Copy for Id<T>
impl<T: Eq> Eq for Id<T>
impl<T> StructuralPartialEq for Id<T>
Auto Trait Implementations§
impl<T> Freeze for Id<T>
impl<T> RefUnwindSafe for Id<T>where
T: RefUnwindSafe,
impl<T> Send for Id<T>where
T: Send,
impl<T> Sync for Id<T>where
T: Sync,
impl<T> Unpin for Id<T>where
T: Unpin,
impl<T> UnwindSafe for Id<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)