pub struct NonNilUuid(/* private fields */);Expand description
A UUID that is guaranteed not to be the nil UUID.
This is useful for representing optional UUIDs more efficiently, as Option<NonNilUuid>
takes up the same space as Uuid.
Note that Uuids created by the following methods are guaranteed to be non-nil:
- [
Uuid::new_v1] - [
Uuid::now_v1] - [
Uuid::new_v3] Uuid::new_v4Uuid::new_v5- [
Uuid::new_v6] - [
Uuid::now_v6] Uuid::new_v7Uuid::now_v7- [
Uuid::new_v8]
§ABI
The NonNilUuid type does not yet have a stable ABI. Its representation or alignment
may change. It is currently only guaranteed that NonNilUuid and Option<NonNilUuid>
are the same size as Uuid.
Implementations§
Source§impl NonNilUuid
impl NonNilUuid
Sourcepub const unsafe fn new_unchecked(uuid: Uuid) -> Self
pub const unsafe fn new_unchecked(uuid: Uuid) -> Self
Creates a non-nil without checking whether the value is non-nil. This results in undefined behavior if the value is nil.
§Safety
The value must not be nil.
Sourcepub fn new_v4() -> Self
pub fn new_v4() -> Self
Creates a non-nil random version 4 UUID.
See Uuid::new_v4 for details.
Sourcepub fn new_v5(namespace: &Uuid, name: &[u8]) -> Self
pub fn new_v5(namespace: &Uuid, name: &[u8]) -> Self
Creates a non-nil version 5 UUID from a namespace and name.
See Uuid::new_v5 for details.
Sourcepub fn new_v7(ts: Timestamp) -> Self
pub fn new_v7(ts: Timestamp) -> Self
Creates a non-nil version 7 UUID from a timestamp.
See Uuid::new_v7 for details.
Sourcepub fn now_v7() -> Self
pub fn now_v7() -> Self
Creates a non-nil version 7 UUID from the current time.
See Uuid::now_v7 for details.
Trait Implementations§
Source§impl Clone for NonNilUuid
impl Clone for NonNilUuid
Source§fn clone(&self) -> NonNilUuid
fn clone(&self) -> NonNilUuid
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for NonNilUuid
Source§impl Debug for NonNilUuid
impl Debug for NonNilUuid
Source§impl<'de> Deserialize<'de> for NonNilUuid
impl<'de> Deserialize<'de> for NonNilUuid
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>,
Source§impl Display for NonNilUuid
impl Display for NonNilUuid
impl Eq for NonNilUuid
Source§impl From<NonNilUuid> for Uuid
impl From<NonNilUuid> for Uuid
Source§fn from(non_nil: NonNilUuid) -> Self
fn from(non_nil: NonNilUuid) -> Self
Converts a NonNilUuid back into a Uuid.
§Examples
let uuid = Uuid::from_u128(0x0123456789abcdef0123456789abcdef);
let non_nil = NonNilUuid::try_from(uuid).unwrap();
let uuid_again = Uuid::from(non_nil);
assert_eq!(uuid, uuid_again);