Struct nuuid::Uuid [−][src]
#[repr(transparent)]pub struct Uuid(_);
Universally Unique Identifier, or UUID.
This type is repr(transparent)
and guaranteed to have the same layout
as [u8; 16]
.
The various methods on Uuid
assume each field
is laid out Most Significant Byte First/MSB/Big-Endian/Network Endian.
This type is also serde(transparent)
, when serde is enabled.
Implementations
impl Uuid
[src]
impl Uuid
[src]pub const fn nil() -> Self
[src]
The special Nil UUID, where all bits are set to zero.
pub const fn from_bytes(bytes: Bytes) -> Self
[src]
Create a UUID from bytes.
pub const fn to_bytes(self) -> Bytes
[src]
Return the UUID as it’s bytes.
pub fn from_bytes_me(bytes: Bytes) -> Self
[src]
Create a UUID from mixed-endian bytes.
Note
This is primarily for compatibility with version 2 UUID’s, which use a mixed-endian format where the first three fields are little-endian.
Common modern use of this format is found in Microsoft GUID’s and UEFI UUID’s.
pub fn to_bytes_me(self) -> Bytes
[src]
Return the UUID as mixed-endian bytes.
See Uuid::from_bytes_me
for details.
pub fn is_nil(self) -> bool
[src]
Returns true if the UUID is nil.
pub fn variant(self) -> Variant
[src]
The UUID Variant
Warning
Many UUIDs out in the wild are incorrectly generated, so this value can’t be relied upon.
pub fn version(self) -> Version
[src]
The UUID Version
Warning
Many UUIDs out in the wild are incorrectly generated, so this value can’t be relied upon.
pub fn to_str(self, buf: &mut [u8; 36]) -> &mut str
[src]
Write UUID as a lowercase ASCII string into buf
, and returns it as a
string.
Examples
With an array
let mut buf = [0u8; 36]; uuid.to_str(&mut buf);
With a slice
let mut buf = [0u8; 50]; let buf: &mut [u8] = &mut buf; uuid.to_str((&mut buf[..36]).try_into().unwrap());
With a slice, incorrectly.
let mut buf = [0u8; 50]; let buf: &mut [u8] = &mut buf; uuid.to_str(buf.try_into().unwrap());
pub fn to_urn(self, buf: &mut [u8; 45]) -> &mut str
[src]
Write a UUID as a lowercase ASCII string into buf
, and return it as a
string.
For usage examples see Uuid::to_str
.
pub fn to_str_upper(self, buf: &mut [u8; 36]) -> &mut str
[src]
Uuid::to_str
, but uppercase.
pub fn to_urn_upper(self, buf: &mut [u8; 45]) -> &mut str
[src]
Uuid::to_urn
, but the UUID is uppercase.
impl Uuid
[src]
impl Uuid
[src]pub fn parse(s: &str) -> Result<Self, ParseUuidError>
[src]
Parse a Uuid
from a string
Case insensitive and supports “urn:uuid:”
Example
Uuid::parse("662aa7c7-7598-4d56-8bcc-a72c30f998a2").unwrap(); Uuid::parse("662AA7C7-7598-4D56-8BCC-A72C30F998A2").unwrap(); Uuid::parse("urn:uuid:662aa7c7-7598-4d56-8bcc-a72c30f998a2").unwrap(); Uuid::parse("urn:uuid:662AA7C7-7598-4D56-8BCC-A72C30F998A2").unwrap();
pub fn new_v4() -> Self
[src]
getrandom
only.Create a new Version 4(Random) UUID.
This requires the getrandom
feature.
If generating a lot of UUID’s very quickly, prefer Uuid::new_v4_rng
.
Example
let uuid = Uuid::new_v4();
pub fn new_v4_rng(rng: &mut Rng) -> Self
[src]
Create a new Version 4(Random) UUID, using the provided Rng
This method is useful if you need to generate a lot of UUID’s very quickly, since it won’t create and seed a new RNG each time.
Providing a good seed is left to you, however. If a bad seed is used, the resulting UUIDs may not be sufficiently random or unique.
Example
let mut rng = Rng::from_seed(seed); for _ in 0..10 { let uuid = Uuid::new_v4_rng(&mut rng); }
pub fn new_v3(namespace: Uuid, name: &[u8]) -> Self
[src]
Create a new Version 3 UUID with the provided name and namespace.
Note
Version 3 UUID’s use the obsolete MD5 algorithm,
Uuid::new_v5
should be preferred.
Example
let uuid = Uuid::new_v3(NAMESPACE_DNS, b"example.com");
pub fn new_v5(namespace: Uuid, name: &[u8]) -> Self
[src]
Create a new Version 5 UUID with the provided name and namespace.
Example
let uuid = Uuid::new_v5(NAMESPACE_DNS, b"example.com");
Trait Implementations
impl Display for Uuid
[src]
impl Display for Uuid
[src]impl FromStr for Uuid
[src]
impl FromStr for Uuid
[src]See Uuid::parse
for details.
impl LowerHex for Uuid
[src]
impl LowerHex for Uuid
[src]Display the Uuid
in lowercase
The alternate(#
) flag can be used to get a URN.
Example
let uuid = Uuid::parse("662aa7c7-7598-4d56-8bcc-a72c30f998a2").unwrap(); assert_eq!(format!("{:x}", uuid), "662aa7c7-7598-4d56-8bcc-a72c30f998a2"); assert_eq!(format!("{:#x}", uuid), "urn:uuid:662aa7c7-7598-4d56-8bcc-a72c30f998a2");
impl PartialOrd<Uuid> for Uuid
[src]
impl PartialOrd<Uuid> for Uuid
[src]impl StructuralEq for Uuid
[src]
impl StructuralEq for Uuid
[src]impl StructuralPartialEq for Uuid
[src]
impl StructuralPartialEq for Uuid
[src]impl UpperHex for Uuid
[src]
impl UpperHex for Uuid
[src]Display the Uuid
in uppercase
The alternate(#
) flag can be used to get a URN.
Example
let uuid = Uuid::parse("662aa7c7-7598-4d56-8bcc-a72c30f998a2").unwrap(); assert_eq!(format!("{:X}", uuid), "662AA7C7-7598-4D56-8BCC-A72C30F998A2"); assert_eq!(format!("{:#X}", uuid), "urn:uuid:662AA7C7-7598-4D56-8BCC-A72C30F998A2");
Auto Trait Implementations
impl RefUnwindSafe for Uuid
impl RefUnwindSafe for Uuid
impl UnwindSafe for Uuid
impl UnwindSafe for Uuid
Blanket Implementations
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,