#[repr(transparent)]pub struct Uuid { /* private fields */ }
Expand description
Universally unique identifier, consisting of 128-bits, as according to RFC4122
Implementations
sourceimpl Uuid
impl Uuid
sourcepub const fn from_bytes(data: [u8; 16]) -> Self
pub const fn from_bytes(data: [u8; 16]) -> Self
Creates new Uuid from raw bytes.
sourcepub const fn from_slice(data: &[u8]) -> Option<Uuid>
pub const fn from_slice(data: &[u8]) -> Option<Uuid>
Creates new Uuid from byte slice, if its size is 16, otherwise None
sourcepub const fn from_guid(d1: u32, d2: u16, d3: u16, d4: [u8; 8]) -> Self
pub const fn from_guid(d1: u32, d2: u16, d3: u16, d4: [u8; 8]) -> Self
Creates UUID
from GUID
converting integer fields to big endian while d4
is copied as
it is.
Note that it is assumed that GUID
was correctly created in little endian format (e.g.
using winapi CoCreateGuid
which internally uses UuidCreate
which in turn relies on
secure random)
Effectively winapi GUID
would result in creation of UUID
of Random
variant.
sourcepub const fn as_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub const fn as_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Access underlying bytes as slice.
sourcepub const fn time_low(&self) -> u32
pub const fn time_low(&self) -> u32
Returns time_low
part of uuid.
Refer to https://en.wikipedia.org/wiki/Universally_unique_identifier#Format
sourcepub const fn time_mid(&self) -> u16
pub const fn time_mid(&self) -> u16
Returns time_mid
part of uuid.
Refer to https://en.wikipedia.org/wiki/Universally_unique_identifier#Format
sourcepub const fn time_high_and_version(&self) -> u16
pub const fn time_high_and_version(&self) -> u16
Returns time_high_and_version
part of uuid.
Refer to https://en.wikipedia.org/wiki/Universally_unique_identifier#Format
sourcepub const fn clock_sequence(&self) -> u16
pub const fn clock_sequence(&self) -> u16
Returns clock_sequence
part of uuid.
Refer to https://en.wikipedia.org/wiki/Universally_unique_identifier#Format
sourcepub const fn node(&self) -> [u8; 6]
pub const fn node(&self) -> [u8; 6]
Returns node
part of uuid.
Refer to https://en.wikipedia.org/wiki/Universally_unique_identifier#Format
sourcepub const fn is_version(&self, version: Version) -> bool
pub const fn is_version(&self, version: Version) -> bool
Checks if UUID
version is equal to the provided version
sourcepub const fn is_variant(&self) -> bool
pub const fn is_variant(&self) -> bool
Checks if UUID
variant is set, only cares about RFC4122 byte
sourcepub const fn v1(timestamp: Timestamp, mac: [u8; 6]) -> Self
pub const fn v1(timestamp: Timestamp, mac: [u8; 6]) -> Self
Generates UUID from time and mac address
sourcepub const fn v3(namespace: Uuid, name: &[u8]) -> Self
pub const fn v3(namespace: Uuid, name: &[u8]) -> Self
Generates UUID v3
by using md5
hasher
Only available when md5
feature is enabled.
sourcepub const fn v4_from(random: [u8; 16]) -> Self
pub const fn v4_from(random: [u8; 16]) -> Self
Constructs UUID v4
from provided bytes, assuming they are random.
It is up to user to guarantee that it is random.
This function only sets corresponding bits for v4
sourcepub fn v4() -> Self
pub fn v4() -> Self
Generates UUID v4
using OS RNG from getrandom
Only available when osrng
feature is enabled.
sourcepub fn v4_prng() -> Self
pub fn v4_prng() -> Self
Generates UUID v4
using PRNG from wyhash
Only available when prng
feature is enabled.
This random variant generates predictable UUID, even though they are unique. Which means that each time program starts, it is initialized with the same seed and therefore would repeat UUIDs
This random is useful when you want to generate predictable but unique UUIDs
Otherwise use v4
sourcepub const fn v5(namespace: Uuid, name: &[u8]) -> Self
pub const fn v5(namespace: Uuid, name: &[u8]) -> Self
Generates UUID v5
by using sha1
hasher
Only available when sha1
feature is enabled.
sourcepub const fn set_variant(self) -> Self
pub const fn set_variant(self) -> Self
Adds variant byte to the corresponding field.
This implementation only cares about RFC4122, there is no option to set other variant.
Useful when user is supplied with random bytes, and wants to create UUID from it.
sourcepub const fn set_version(self, version: Version) -> Self
pub const fn set_version(self, version: Version) -> Self
Adds version byte to the corresponding field.
Useful when user is supplied with random bytes, and wants to create UUID from it.
sourcepub const fn parse_ascii_bytes(input: &[u8]) -> Result<Self, ParseError>
pub const fn parse_ascii_bytes(input: &[u8]) -> Result<Self, ParseError>
Creates new instance by parsing provided bytes.
Use this when you want to avoid performing utf-8 checks and directly feed bytes. As long as supplied bytes contain valid ascii characters it will parse successfully. Otherwise it shall fail with invalid character.
Supports only simple sequence of characters and -
separated.
sourcepub const fn parse_str(input: &str) -> Result<Self, ParseError>
pub const fn parse_str(input: &str) -> Result<Self, ParseError>
Creates new instance by parsing provided string.
Supports only simple sequence of characters and -
separated.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Uuid
impl<'de> Deserialize<'de> for Uuid
sourcefn deserialize<D: Deserializer<'de>>(des: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(des: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Ord for Uuid
impl Ord for Uuid
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<Uuid> for Uuid
impl PartialEq<Uuid> for Uuid
sourceimpl PartialOrd<Uuid> for Uuid
impl PartialOrd<Uuid> for Uuid
sourcefn partial_cmp(&self, other: &Uuid) -> Option<Ordering>
fn partial_cmp(&self, other: &Uuid) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn 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
impl Copy for Uuid
impl Eq for Uuid
impl StructuralEq for Uuid
impl StructuralPartialEq for Uuid
Auto Trait Implementations
impl RefUnwindSafe for Uuid
impl Send for Uuid
impl Sync for Uuid
impl Unpin for Uuid
impl UnwindSafe for Uuid
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more