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]

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]

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]

This is supported on crate feature 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 AsRef<[u8; 16]> for Uuid[src]

impl AsRef<[u8]> for Uuid[src]

impl Clone for Uuid[src]

impl Copy for Uuid[src]

impl Debug for Uuid[src]

impl Default for Uuid[src]

impl Display for Uuid[src]

Display the Uuid in uppercase hex.

Example

let uuid = Uuid::parse("662aa7c7-7598-4d56-8bcc-a72c30f998a2").unwrap();
assert_eq!(format!("{}", uuid), "662AA7C7-7598-4D56-8BCC-A72C30F998A2");

impl Eq for Uuid[src]

impl FromStr for Uuid[src]

See Uuid::parse for details.

type Err = ParseUuidError

The associated error which can be returned from parsing.

impl Hash 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 Ord for Uuid[src]

impl PartialEq<Uuid> for Uuid[src]

impl PartialOrd<Uuid> for Uuid[src]

impl StructuralEq for Uuid[src]

impl StructuralPartialEq 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 Send for Uuid

impl Sync for Uuid

impl Unpin for Uuid

impl UnwindSafe for Uuid

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,