Files
blackwriter-server/doc/uuid.md
PIVODEVAT 059fbda921 init
2025-12-13 22:28:05 +03:00

56 KiB

Crate Documentation

Version: 1.19.0

Format Version: 57

Module uuid

Generate and parse universally unique identifiers (UUIDs).

Here's an example of a UUID:

67e55044-10b1-426f-9247-bb680e5fe0c8

A UUID is a unique 128-bit value, stored as 16 octets, and regularly formatted as a hex string in five groups. UUIDs are used to assign unique identifiers to entities without requiring a central allocating authority.

They are particularly useful in distributed systems, though can be used in disparate areas, such as databases and network protocols. Typically a UUID is displayed in a readable string form as a sequence of hexadecimal digits, separated into groups by hyphens.

The uniqueness property is not strictly guaranteed, however for all practical purposes, it can be assumed that an unintentional collision would be extremely unlikely.

UUIDs have a number of standardized encodings that are specified in RFC 9562.

Getting started

Add the following to your Cargo.toml:

[dependencies.uuid]
version = "1.19.0"
# Lets you generate random UUIDs
features = [
    "v4",
]

When you want a UUID, you can generate one:

# fn main() {
# #[cfg(feature = "v4")]
# {
use uuid::Uuid;

let id = Uuid::new_v4();
# }
# }

If you have a UUID value, you can use its string literal form inline:

use uuid::{uuid, Uuid};

const ID: Uuid = uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8");

Working with different UUID versions

This library supports all standardized methods for generating UUIDs through individual Cargo features.

By default, this crate depends on nothing but the Rust standard library and can parse and format UUIDs, but cannot generate them. Depending on the kind of UUID you'd like to work with, there are Cargo features that enable generating them:

  • v1 - Version 1 UUIDs using a timestamp and monotonic counter.
  • v3 - Version 3 UUIDs based on the MD5 hash of some data.
  • v4 - Version 4 UUIDs with random data.
  • v5 - Version 5 UUIDs based on the SHA1 hash of some data.
  • v6 - Version 6 UUIDs using a timestamp and monotonic counter.
  • v7 - Version 7 UUIDs using a Unix timestamp.
  • v8 - Version 8 UUIDs using user-defined data.

This library also includes a [Builder] type that can be used to help construct UUIDs of any version without any additional dependencies or features. It's a lower-level API than [Uuid] that can be used when you need control over implicit requirements on things like a source of randomness.

Which UUID version should I use?

If you just want to generate unique identifiers then consider version 4 (v4) UUIDs. If you want to use UUIDs as database keys or need to sort them then consider version 7 (v7) UUIDs. Other versions should generally be avoided unless there's an existing need for them.

Some UUID versions supersede others. Prefer version 6 over version 1 and version 5 over version 3.

Other features

Other crate features can also be useful beyond the version support:

  • macro-diagnostics - enhances the diagnostics of uuid! macro.
  • serde - adds the ability to serialize and deserialize a UUID using serde.
  • borsh - adds the ability to serialize and deserialize a UUID using borsh.
  • arbitrary - adds an Arbitrary trait implementation to Uuid for fuzzing.
  • fast-rng - uses a faster algorithm for generating random UUIDs when available. This feature requires more dependencies to compile, but is just as suitable for UUIDs as the default algorithm.
  • rng-rand - forces rand as the backend for randomness.
  • rng-getrandom - forces getrandom as the backend for randomness.
  • bytemuck - adds a Pod trait implementation to Uuid for byte manipulation

Unstable features

Some features are unstable. They may be incomplete or depend on other unstable libraries. These include:

  • zerocopy - adds support for zero-copy deserialization using the zerocopy library.

Unstable features may break between minor releases.

To allow unstable features, you'll need to enable the Cargo feature as normal, but also pass an additional flag through your environment to opt-in to unstable uuid features:

RUSTFLAGS="--cfg uuid_unstable"

Building for other targets

WebAssembly

For WebAssembly, enable the js feature:

[dependencies.uuid]
version = "1.19.0"
features = [
    "v4",
    "v7",
    "js",
]

Embedded

For embedded targets without the standard library, you'll need to disable default features when building uuid:

[dependencies.uuid]
version = "1.19.0"
default-features = false

Some additional features are supported in no-std environments:

  • v1, v3, v5, v6, and v8.
  • serde.

If you need to use v4 or v7 in a no-std environment, you'll need to produce random bytes yourself and then pass them to [Builder::from_random_bytes] without enabling the v4 or v7 features.

If you're using getrandom, you can specify the rng-getrandom or rng-rand features of uuid and configure getrandom's provider per its docs. uuid may upgrade its version of getrandom in minor releases.

Examples

Parse a UUID given in the simple format and print it as a URN:

# use uuid::Uuid;
# fn main() -> Result<(), uuid::Error> {
let my_uuid = Uuid::parse_str("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8")?;

println!("{}", my_uuid.urn());
# Ok(())
# }

Generate a random UUID and print it out in hexadecimal form:

// Note that this requires the `v4` feature to be enabled.
# use uuid::Uuid;
# fn main() {
# #[cfg(feature = "v4")] {
let my_uuid = Uuid::new_v4();

println!("{}", my_uuid);
# }
# }

References

Modules

Module fmt

Adapters for alternative string formats.

pub mod fmt { /* ... */ }

Types

Struct Hyphenated

Attributes:

  • Other("#[<cfg_attr_trace>(all(uuid_unstable, feature = \"zerocopy\"),\nderive(zerocopy::IntoBytes, zerocopy::FromBytes, zerocopy::KnownLayout,\nzerocopy::Immutable, zerocopy::Unaligned))]")
  • Repr(AttributeRepr { kind: Transparent, align: None, packed: None, int: None })

Format a [Uuid] as a hyphenated string, like 67e55044-10b1-426f-9247-bb680e5fe0c8.

pub struct Hyphenated(/* private field */);
Fields
Index Type Documentation
0 private Private field
Implementations
Methods
  • pub const fn from_uuid(uuid: Uuid) -> Self { /* ... */ }
    

    Creates a [Hyphenated] from a [Uuid].

  • pub fn encode_lower<''buf>(self: &Self, buffer: &''buf mut [u8]) -> &''buf mut str { /* ... */ }
    

    Writes the [Uuid] as a lower-case hyphenated string to

  • pub fn encode_upper<''buf>(self: &Self, buffer: &''buf mut [u8]) -> &''buf mut str { /* ... */ }
    

    Writes the [Uuid] as an upper-case hyphenated string to

  • pub const fn as_uuid(self: &Self) -> &Uuid { /* ... */ }
    

    Get a reference to the underlying [Uuid].

  • pub const fn into_uuid(self: Self) -> Uuid { /* ... */ }
    

    Consumes the [Hyphenated], returning the underlying [Uuid].

Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • AsRef

    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
    • fn borrow(self: &Self) -> &Uuid { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> Hyphenated { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
      
  • Default

    • fn default() -> Hyphenated { /* ... */ }
      
  • Display

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Eq

  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      

      Returns the argument unchanged.

    • fn from(f: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Hyphenated) -> Self { /* ... */ }
      
  • FromStr

    • fn from_str(s: &str) -> Result<Self, <Self as >::Err> { /* ... */ }
      
  • Hash

    • fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H) { /* ... */ }
      
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • LowerHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Ord

    • fn cmp(self: &Self, other: &Hyphenated) -> $crate::cmp::Ordering { /* ... */ }
      
  • PartialEq

    • fn eq(self: &Self, other: &Hyphenated) -> bool { /* ... */ }
      
  • PartialOrd

    • fn partial_cmp(self: &Self, other: &Hyphenated) -> $crate::option::Option<$crate::cmp::Ordering> { /* ... */ }
      
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • Serialize

    • fn erased_serialize(self: &Self, serializer: &mut dyn Serializer) -> Result<Ok, Error> { /* ... */ }
      
    • fn serialize<S: Serializer>(self: &Self, serializer: S) -> Result<<S as >::Ok, <S as >::Error> { /* ... */ }
      
  • StructuralPartialEq

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • ToString

    • fn to_string(self: &Self) -> String { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

  • UpperHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      

Struct Simple

Attributes:

  • Other("#[<cfg_attr_trace>(all(uuid_unstable, feature = \"zerocopy\"),\nderive(zerocopy::IntoBytes, zerocopy::FromBytes, zerocopy::KnownLayout,\nzerocopy::Immutable, zerocopy::Unaligned))]")
  • Repr(AttributeRepr { kind: Transparent, align: None, packed: None, int: None })

Format a [Uuid] as a simple string, like 67e5504410b1426f9247bb680e5fe0c8.

pub struct Simple(/* private field */);
Fields
Index Type Documentation
0 private Private field
Implementations
Methods
  • pub const fn from_uuid(uuid: Uuid) -> Self { /* ... */ }
    

    Creates a [Simple] from a [Uuid].

  • pub fn encode_lower<''buf>(self: &Self, buffer: &''buf mut [u8]) -> &''buf mut str { /* ... */ }
    

    Writes the [Uuid] as a lower-case simple string to buffer,

  • pub fn encode_upper<''buf>(self: &Self, buffer: &''buf mut [u8]) -> &''buf mut str { /* ... */ }
    

    Writes the [Uuid] as an upper-case simple string to buffer,

  • pub const fn as_uuid(self: &Self) -> &Uuid { /* ... */ }
    

    Get a reference to the underlying [Uuid].

  • pub const fn into_uuid(self: Self) -> Uuid { /* ... */ }
    

    Consumes the [Simple], returning the underlying [Uuid].

Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • AsRef

    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
    • fn borrow(self: &Self) -> &Uuid { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> Simple { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
      
  • Default

    • fn default() -> Simple { /* ... */ }
      
  • Display

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Eq

  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      

      Returns the argument unchanged.

    • fn from(f: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Simple) -> Self { /* ... */ }
      
  • FromStr

    • fn from_str(s: &str) -> Result<Self, <Self as >::Err> { /* ... */ }
      
  • Hash

    • fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H) { /* ... */ }
      
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • LowerHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Ord

    • fn cmp(self: &Self, other: &Simple) -> $crate::cmp::Ordering { /* ... */ }
      
  • PartialEq

    • fn eq(self: &Self, other: &Simple) -> bool { /* ... */ }
      
  • PartialOrd

    • fn partial_cmp(self: &Self, other: &Simple) -> $crate::option::Option<$crate::cmp::Ordering> { /* ... */ }
      
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • Serialize

    • fn erased_serialize(self: &Self, serializer: &mut dyn Serializer) -> Result<Ok, Error> { /* ... */ }
      
    • fn serialize<S: Serializer>(self: &Self, serializer: S) -> Result<<S as >::Ok, <S as >::Error> { /* ... */ }
      
  • StructuralPartialEq

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • ToString

    • fn to_string(self: &Self) -> String { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

  • UpperHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      

Struct Urn

Attributes:

  • Other("#[<cfg_attr_trace>(all(uuid_unstable, feature = \"zerocopy\"),\nderive(zerocopy::IntoBytes, zerocopy::FromBytes, zerocopy::KnownLayout,\nzerocopy::Immutable, zerocopy::Unaligned))]")
  • Repr(AttributeRepr { kind: Transparent, align: None, packed: None, int: None })

Format a [Uuid] as a URN string, like urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8.

pub struct Urn(/* private field */);
Fields
Index Type Documentation
0 private Private field
Implementations
Methods
  • pub const fn from_uuid(uuid: Uuid) -> Self { /* ... */ }
    

    Creates a [Urn] from a [Uuid].

  • pub fn encode_lower<''buf>(self: &Self, buffer: &''buf mut [u8]) -> &''buf mut str { /* ... */ }
    

    Writes the [Uuid] as a lower-case URN string to

  • pub fn encode_upper<''buf>(self: &Self, buffer: &''buf mut [u8]) -> &''buf mut str { /* ... */ }
    

    Writes the [Uuid] as an upper-case URN string to

  • pub const fn as_uuid(self: &Self) -> &Uuid { /* ... */ }
    

    Get a reference to the underlying [Uuid].

  • pub const fn into_uuid(self: Self) -> Uuid { /* ... */ }
    

    Consumes the [Urn], returning the underlying [Uuid].

Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • AsRef

    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
    • fn borrow(self: &Self) -> &Uuid { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> Urn { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
      
  • Default

    • fn default() -> Urn { /* ... */ }
      
  • Display

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Eq

  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      

      Returns the argument unchanged.

    • fn from(f: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Urn) -> Self { /* ... */ }
      
  • FromStr

    • fn from_str(s: &str) -> Result<Self, <Self as >::Err> { /* ... */ }
      
  • Hash

    • fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H) { /* ... */ }
      
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • LowerHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Ord

    • fn cmp(self: &Self, other: &Urn) -> $crate::cmp::Ordering { /* ... */ }
      
  • PartialEq

    • fn eq(self: &Self, other: &Urn) -> bool { /* ... */ }
      
  • PartialOrd

    • fn partial_cmp(self: &Self, other: &Urn) -> $crate::option::Option<$crate::cmp::Ordering> { /* ... */ }
      
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • Serialize

    • fn erased_serialize(self: &Self, serializer: &mut dyn Serializer) -> Result<Ok, Error> { /* ... */ }
      
    • fn serialize<S: Serializer>(self: &Self, serializer: S) -> Result<<S as >::Ok, <S as >::Error> { /* ... */ }
      
  • StructuralPartialEq

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • ToString

    • fn to_string(self: &Self) -> String { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

  • UpperHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      

Struct Braced

Attributes:

  • Other("#[<cfg_attr_trace>(all(uuid_unstable, feature = \"zerocopy\"),\nderive(zerocopy::IntoBytes, zerocopy::FromBytes, zerocopy::KnownLayout,\nzerocopy::Immutable, zerocopy::Unaligned))]")
  • Repr(AttributeRepr { kind: Transparent, align: None, packed: None, int: None })

Format a [Uuid] as a braced hyphenated string, like {67e55044-10b1-426f-9247-bb680e5fe0c8}.

pub struct Braced(/* private field */);
Fields
Index Type Documentation
0 private Private field
Implementations
Methods
  • pub const fn from_uuid(uuid: Uuid) -> Self { /* ... */ }
    

    Creates a [Braced] from a [Uuid].

  • pub fn encode_lower<''buf>(self: &Self, buffer: &''buf mut [u8]) -> &''buf mut str { /* ... */ }
    

    Writes the [Uuid] as a lower-case hyphenated string surrounded by

  • pub fn encode_upper<''buf>(self: &Self, buffer: &''buf mut [u8]) -> &''buf mut str { /* ... */ }
    

    Writes the [Uuid] as an upper-case hyphenated string surrounded by

  • pub const fn as_uuid(self: &Self) -> &Uuid { /* ... */ }
    

    Get a reference to the underlying [Uuid].

  • pub const fn into_uuid(self: Self) -> Uuid { /* ... */ }
    

    Consumes the [Braced], returning the underlying [Uuid].

Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • AsRef

    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
    • fn borrow(self: &Self) -> &Uuid { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> Braced { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
      
  • Default

    • fn default() -> Braced { /* ... */ }
      
  • Display

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Eq

  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      

      Returns the argument unchanged.

    • fn from(f: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Braced) -> Self { /* ... */ }
      
  • FromStr

    • fn from_str(s: &str) -> Result<Self, <Self as >::Err> { /* ... */ }
      
  • Hash

    • fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H) { /* ... */ }
      
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • LowerHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Ord

    • fn cmp(self: &Self, other: &Braced) -> $crate::cmp::Ordering { /* ... */ }
      
  • PartialEq

    • fn eq(self: &Self, other: &Braced) -> bool { /* ... */ }
      
  • PartialOrd

    • fn partial_cmp(self: &Self, other: &Braced) -> $crate::option::Option<$crate::cmp::Ordering> { /* ... */ }
      
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • Serialize

    • fn erased_serialize(self: &Self, serializer: &mut dyn Serializer) -> Result<Ok, Error> { /* ... */ }
      
    • fn serialize<S: Serializer>(self: &Self, serializer: S) -> Result<<S as >::Ok, <S as >::Error> { /* ... */ }
      
  • StructuralPartialEq

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • ToString

    • fn to_string(self: &Self) -> String { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

  • UpperHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      

Module timestamp

Generating UUIDs from timestamps.

Timestamps are used in a few UUID versions as a source of decentralized uniqueness (as in versions 1 and 6), and as a way to enable sorting (as in versions 6 and 7). Timestamps aren't encoded the same way by all UUID versions so this module provides a single [Timestamp] type that can convert between them.

Timestamp representations in UUIDs

Versions 1 and 6 UUIDs use a bespoke timestamp that consists of the number of 100ns ticks since 1582-10-15 00:00:00, along with a counter value to avoid duplicates.

Version 7 UUIDs use a more standard timestamp that consists of the number of millisecond ticks since the Unix epoch (1970-01-01 00:00:00).

References

pub mod timestamp { /* ... */ }

Modules

Module context

Default implementations for the [ClockSequence] trait.

pub mod context { /* ... */ }

Types

Struct NoContext

An empty counter that will always return the value 0.

This type can be used when constructing version 7 UUIDs. When used to construct a version 7 UUID, the entire counter segment of the UUID will be filled with a random value. This type does not maintain ordering of UUIDs within a millisecond but is efficient.

This type should not be used when constructing version 1 or version 6 UUIDs. When used to construct a version 1 or version 6 UUID, the counter segment will remain zero.

pub struct NoContext;
Implementations
Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • ClockSequence

    • fn generate_sequence(self: &Self, _seconds: u64, _nanos: u32) -> <Self as >::Output { /* ... */ }
      
    • fn usable_bits(self: &Self) -> usize { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> NoContext { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
      
  • Default

    • fn default() -> NoContext { /* ... */ }
      
  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      
      Returns the argument unchanged.
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

Re-exports

Re-export v1_support::*

Attributes:

  • Other("#[<cfg_trace>(any(feature = \"v1\", feature = \"v6\"))]")
pub use v1_support::*;

Re-export std_support::*

Attributes:

  • Other("#[<cfg_trace>(feature = \"std\")]")
pub use std_support::*;

Re-export v7_support::*

Attributes:

  • Other("#[<cfg_trace>(feature = \"v7\")]")
pub use v7_support::*;

Types

Struct Timestamp

A timestamp that can be encoded into a UUID.

This type abstracts the specific encoding, so versions 1, 6, and 7 UUIDs can both be supported through the same type, even though they have a different representation of a timestamp.

References

pub struct Timestamp {
    // Some fields omitted
}
Fields
Name Type Documentation
private fields ... Some fields have been omitted
Implementations
Methods
  • pub fn now</* synthetic */ impl Into<u128>: Into<u128>, /* synthetic */ impl ClockSequence<Output = impl Into<u128>>: ClockSequence<Output = impl Into<u128>>>(context: impl ClockSequence<Output = impl Into<u128>>) -> Self { /* ... */ }
    

    Get a timestamp representing the current system time and up to a 128-bit counter.

  • pub const fn from_gregorian(ticks: u64, counter: u16) -> Self { /* ... */ }
    

    Construct a Timestamp from the number of 100 nanosecond ticks since 00:00:00.00,

  • pub const fn from_unix_time(seconds: u64, subsec_nanos: u32, counter: u128, usable_counter_bits: u8) -> Self { /* ... */ }
    

    Construct a Timestamp from a Unix timestamp and up to a 128-bit counter, as used in version 7 UUIDs.

  • pub fn from_unix</* synthetic */ impl Into<u128>: Into<u128>, /* synthetic */ impl ClockSequence<Output = impl Into<u128>>: ClockSequence<Output = impl Into<u128>>>(context: impl ClockSequence<Output = impl Into<u128>>, seconds: u64, subsec_nanos: u32) -> Self { /* ... */ }
    

    Construct a Timestamp from a Unix timestamp and up to a 128-bit counter, as used in version 7 UUIDs.

  • pub const fn to_gregorian(self: &Self) -> (u64, u16) { /* ... */ }
    

    Get the value of the timestamp as the number of 100 nanosecond ticks since 00:00:00.00,

  • pub const fn to_unix(self: &Self) -> (u64, u32) { /* ... */ }
    

    Get the value of the timestamp as a Unix timestamp, as used in version 7 UUIDs.

Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> Timestamp { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
      
  • Eq

  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      

      Returns the argument unchanged.

    • fn from(ts: Timestamp) -> Self { /* ... */ }
      
  • Hash

    • fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H) { /* ... */ }
      
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • PartialEq

    • fn eq(self: &Self, other: &Timestamp) -> bool { /* ... */ }
      
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • StructuralPartialEq

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
    • fn try_from(st: std::time::SystemTime) -> Result<Self, <Self as >::Error> { /* ... */ }
      

      Perform the conversion.

  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

Traits

Trait ClockSequence

A counter that can be used by versions 1 and 6 UUIDs to support the uniqueness of timestamps.

References

pub trait ClockSequence {
    /* Associated items */
}
Required Items
Associated Types
  • Output: The type of sequence returned by this counter.
Required Methods
  • generate_sequence: Get the next value in the sequence to feed into a timestamp.
Provided Methods
  • fn generate_timestamp_sequence(self: &Self, seconds: u64, subsec_nanos: u32) -> (<Self as >::Output, u64, u32) { /* ... */ }
    

    Get the next value in the sequence, potentially also adjusting the timestamp.

  • fn usable_bits(self: &Self) -> usize
    

where ::Output: Sized { /* ... */ }

The number of usable bits from the least significant bit in the result of [`ClockSequence::generate_sequence`]

##### Implementations

This trait is implemented for the following types:

- `&T` with <T: ClockSequence + ?Sized>
- `Context`
- `ThreadLocalContext<C>` with <C: ClockSequence + ''static>
- `core::panic::AssertUnwindSafe<C>` with <C: ClockSequence>
- `std::sync::Mutex<C>` with <C: ClockSequence + RefUnwindSafe>
- `ContextV7`
- `NoContext`

### Constants and Statics

#### Constant `UUID_TICKS_BETWEEN_EPOCHS`

The number of 100 nanosecond ticks between the RFC 9562 epoch
(`1582-10-15 00:00:00`) and the Unix epoch (`1970-01-01 00:00:00`).

```rust
pub const UUID_TICKS_BETWEEN_EPOCHS: u64 = 0x01B2_1DD2_1381_4000;

Module serde

Attributes:

  • Other("#[<cfg_trace>(feature = \"serde\")]")

Adapters for alternative serde formats.

This module contains adapters you can use with #[serde(with)] to change the way a Uuid is serialized and deserialized.

pub mod serde { /* ... */ }

Re-exports

Re-export braced

pub use crate::external::serde_support::braced;

Re-export compact

pub use crate::external::serde_support::compact;

Re-export simple

pub use crate::external::serde_support::simple;

Re-export urn

pub use crate::external::serde_support::urn;

Types

Type Alias Bytes

A 128-bit (16 byte) buffer containing the UUID.

ABI

The Bytes type is always guaranteed to be have the same ABI as [Uuid].

pub type Bytes = [u8; 16];

Enum Version

Attributes:

  • Repr(AttributeRepr { kind: Rust, align: None, packed: None, int: Some("u8") })
  • NonExhaustive

The version of the UUID, denoting the generating algorithm.

References

pub enum Version {
    Nil = 0u8,
    Mac = 1,
    Dce = 2,
    Md5 = 3,
    Random = 4,
    Sha1 = 5,
    SortMac = 6,
    SortRand = 7,
    Custom = 8,
    Max = 0xff,
}

Variants

Nil

The "nil" (all zeros) UUID.

Discriminant: 0u8

Discriminant value: 0

Mac

Version 1: Timestamp and node ID.

Discriminant: 1

Discriminant value: 1

Dce

Version 2: DCE Security.

Discriminant: 2

Discriminant value: 2

Md5

Version 3: MD5 hash.

Discriminant: 3

Discriminant value: 3

Random

Version 4: Random.

Discriminant: 4

Discriminant value: 4

Sha1

Version 5: SHA-1 hash.

Discriminant: 5

Discriminant value: 5

SortMac

Version 6: Sortable Timestamp and node ID.

Discriminant: 6

Discriminant value: 6

SortRand

Version 7: Timestamp and random.

Discriminant: 7

Discriminant value: 7

Custom

Version 8: Custom.

Discriminant: 8

Discriminant value: 8

Max

The "max" (all ones) UUID.

Discriminant: 0xff

Discriminant value: 255

Implementations

Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> Version { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
      
  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      
      Returns the argument unchanged.
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • PartialEq

    • fn eq(self: &Self, other: &Version) -> bool { /* ... */ }
      
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • StructuralPartialEq

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

Enum Variant

Attributes:

  • Repr(AttributeRepr { kind: Rust, align: None, packed: None, int: Some("u8") })
  • NonExhaustive

The reserved variants of UUIDs.

References

pub enum Variant {
    NCS = 0u8,
    RFC4122,
    Microsoft,
    Future,
}

Variants

NCS

Reserved by the NCS for backward compatibility.

Discriminant: 0u8

Discriminant value: 0

RFC4122

As described in the RFC 9562 Specification (default). (for backward compatibility it is not yet renamed)

Microsoft

Reserved by Microsoft for backward compatibility.

Future

Reserved for future expansion.

Implementations

Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> Variant { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
      
  • Display

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      
      Returns the argument unchanged.
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • PartialEq

    • fn eq(self: &Self, other: &Variant) -> bool { /* ... */ }
      
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • StructuralPartialEq

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • ToString

    • fn to_string(self: &Self) -> String { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

Struct Uuid

Attributes:

  • Other("#[<cfg_attr_trace>(feature = \"borsh\",\nderive(borsh_derive::BorshDeserialize, borsh_derive::BorshSerialize))]")
  • Other("#[<cfg_attr_trace>(feature = \"bytemuck\",\nderive(bytemuck::Zeroable, bytemuck::Pod, bytemuck::TransparentWrapper))]")
  • Other("#[<cfg_attr_trace>(all(uuid_unstable, feature = \"zerocopy\"),\nderive(zerocopy::IntoBytes, zerocopy::FromBytes, zerocopy::KnownLayout,\nzerocopy::Immutable, zerocopy::Unaligned))]")
  • Repr(AttributeRepr { kind: Transparent, align: None, packed: None, int: None })

A Universally Unique Identifier (UUID).

Examples

Parse a UUID given in the simple format and print it as a urn:

# use uuid::Uuid;
# fn main() -> Result<(), uuid::Error> {
let my_uuid = Uuid::parse_str("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8")?;

println!("{}", my_uuid.urn());
# Ok(())
# }

Create a new random (V4) UUID and print it out in hexadecimal form:

// Note that this requires the `v4` feature enabled in the uuid crate.
# use uuid::Uuid;
# fn main() {
# #[cfg(feature = "v4")] {
let my_uuid = Uuid::new_v4();

println!("{}", my_uuid);
# }
# }

Formatting

A UUID can be formatted in one of a few ways:

  • simple: a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8.
  • hyphenated: a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8.
  • urn: urn:uuid:A1A2A3A4-B1B2-C1C2-D1D2-D3D4D5D6D7D8.
  • braced: {a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8}.

The default representation when formatting a UUID with Display is hyphenated:

# use uuid::Uuid;
# fn main() -> Result<(), uuid::Error> {
let my_uuid = Uuid::parse_str("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8")?;

assert_eq!(
    "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
    my_uuid.to_string(),
);
# Ok(())
# }

Other formats can be specified using adapter methods on the UUID:

# use uuid::Uuid;
# fn main() -> Result<(), uuid::Error> {
let my_uuid = Uuid::parse_str("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8")?;

assert_eq!(
    "urn:uuid:a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
    my_uuid.urn().to_string(),
);
# Ok(())
# }

Endianness

The specification for UUIDs encodes the integer fields that make up the value in big-endian order. This crate assumes integer inputs are already in the correct order by default, regardless of the endianness of the environment. Most methods that accept integers have a _le variant (such as from_fields_le) that assumes any integer values will need to have their bytes flipped, regardless of the endianness of the environment.

Most users won't need to worry about endianness unless they need to operate on individual fields (such as when converting between Microsoft GUIDs). The important things to remember are:

  • The endianness is in terms of the fields of the UUID, not the environment.
  • The endianness is assumed to be big-endian when there's no _le suffix somewhere.
  • Byte-flipping in _le methods applies to each integer.
  • Endianness roundtrips, so if you create a UUID with from_fields_le you'll get the same values back out with to_fields_le.

ABI

The Uuid type is always guaranteed to be have the same ABI as [Bytes].

pub struct Uuid(/* private field */);

Fields

Index Type Documentation
0 private Private field

Implementations

Methods
  • pub const fn nil() -> Self { /* ... */ }
    

    The 'nil UUID' (all zeros).

  • pub const fn max() -> Self { /* ... */ }
    

    The 'max UUID' (all ones).

  • pub const fn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid { /* ... */ }
    

    Creates a UUID from four field values.

  • pub const fn from_fields_le(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid { /* ... */ }
    

    Creates a UUID from four field values in little-endian order.

  • pub const fn from_u128(v: u128) -> Self { /* ... */ }
    

    Creates a UUID from a 128bit value.

  • pub const fn from_u128_le(v: u128) -> Self { /* ... */ }
    

    Creates a UUID from a 128bit value in little-endian order.

  • pub const fn from_u64_pair(high_bits: u64, low_bits: u64) -> Self { /* ... */ }
    

    Creates a UUID from two 64bit values.

  • pub fn from_slice(b: &[u8]) -> Result<Uuid, Error> { /* ... */ }
    

    Creates a UUID using the supplied bytes.

  • pub fn from_slice_le(b: &[u8]) -> Result<Uuid, Error> { /* ... */ }
    

    Creates a UUID using the supplied bytes in little endian order.

  • pub const fn from_bytes(bytes: Bytes) -> Uuid { /* ... */ }
    

    Creates a UUID using the supplied bytes.

  • pub const fn from_bytes_le(b: Bytes) -> Uuid { /* ... */ }
    

    Creates a UUID using the supplied bytes in little endian order.

  • pub fn from_bytes_ref(bytes: &Bytes) -> &Uuid { /* ... */ }
    

    Creates a reference to a UUID from a reference to the supplied bytes.

  • pub fn parse_str(input: &str) -> Result<Uuid, Error> { /* ... */ }
    

    Parses a Uuid from a string of hexadecimal digits with optional

  • pub const fn try_parse(input: &str) -> Result<Uuid, Error> { /* ... */ }
    

    Parses a Uuid from a string of hexadecimal digits with optional

  • pub const fn try_parse_ascii(input: &[u8]) -> Result<Uuid, Error> { /* ... */ }
    

    Parses a Uuid from a string of hexadecimal digits with optional

  • pub const fn hyphenated(self: Self) -> Hyphenated { /* ... */ }
    

    Get a [Hyphenated] formatter.

  • pub fn as_hyphenated(self: &Self) -> &Hyphenated { /* ... */ }
    

    Get a borrowed [Hyphenated] formatter.

  • pub const fn simple(self: Self) -> Simple { /* ... */ }
    

    Get a [Simple] formatter.

  • pub fn as_simple(self: &Self) -> &Simple { /* ... */ }
    

    Get a borrowed [Simple] formatter.

  • pub const fn urn(self: Self) -> Urn { /* ... */ }
    

    Get a [Urn] formatter.

  • pub fn as_urn(self: &Self) -> &Urn { /* ... */ }
    

    Get a borrowed [Urn] formatter.

  • pub const fn braced(self: Self) -> Braced { /* ... */ }
    

    Get a [Braced] formatter.

  • pub fn as_braced(self: &Self) -> &Braced { /* ... */ }
    

    Get a borrowed [Braced] formatter.

  • pub fn now_v1(node_id: &[u8; 6]) -> Self { /* ... */ }
    

    Create a new version 1 UUID using the current system time and node ID.

  • pub fn new_v1(ts: Timestamp, node_id: &[u8; 6]) -> Self { /* ... */ }
    

    Create a new version 1 UUID using the given timestamp and node ID.

  • pub fn new_v3(namespace: &Uuid, name: &[u8]) -> Uuid { /* ... */ }
    

    Creates a UUID using a name from a namespace, based on the MD5

  • pub fn new_v4() -> Uuid { /* ... */ }
    

    Creates a random UUID.

  • pub fn new_v5(namespace: &Uuid, name: &[u8]) -> Uuid { /* ... */ }
    

    Creates a UUID using a name from a namespace, based on the SHA-1 hash.

  • pub fn now_v6(node_id: &[u8; 6]) -> Self { /* ... */ }
    

    Create a new version 6 UUID using the current system time and node ID.

  • pub fn new_v6(ts: Timestamp, node_id: &[u8; 6]) -> Self { /* ... */ }
    

    Create a new version 6 UUID using the given timestamp and a node ID.

  • pub fn now_v7() -> Self { /* ... */ }
    

    Create a new version 7 UUID using the current time value.

  • pub fn new_v7(ts: Timestamp) -> Self { /* ... */ }
    

    Create a new version 7 UUID using a time value and random bytes.

  • pub const fn new_v8(buf: [u8; 16]) -> Uuid { /* ... */ }
    

    Creates a custom UUID comprised almost entirely of user-supplied bytes.

  • pub const fn get_variant(self: &Self) -> Variant { /* ... */ }
    

    Returns the variant of the UUID structure.

  • pub const fn get_version_num(self: &Self) -> usize { /* ... */ }
    

    Returns the version number of the UUID.

  • pub const fn get_version(self: &Self) -> Option<Version> { /* ... */ }
    

    Returns the version of the UUID.

  • pub fn as_fields(self: &Self) -> (u32, u16, u16, &[u8; 8]) { /* ... */ }
    

    Returns the four field values of the UUID.

  • pub fn to_fields_le(self: &Self) -> (u32, u16, u16, &[u8; 8]) { /* ... */ }
    

    Returns the four field values of the UUID in little-endian order.

  • pub const fn as_u128(self: &Self) -> u128 { /* ... */ }
    

    Returns a 128bit value containing the value.

  • pub const fn to_u128_le(self: &Self) -> u128 { /* ... */ }
    

    Returns a 128bit little-endian value containing the value.

  • pub const fn as_u64_pair(self: &Self) -> (u64, u64) { /* ... */ }
    

    Returns two 64bit values containing the value.

  • pub const fn as_bytes(self: &Self) -> &Bytes { /* ... */ }
    

    Returns a slice of 16 octets containing the value.

  • pub const fn into_bytes(self: Self) -> Bytes { /* ... */ }
    

    Consumes self and returns the underlying byte value of the UUID.

  • pub const fn to_bytes_le(self: &Self) -> Bytes { /* ... */ }
    

    Returns the bytes of the UUID in little-endian order.

  • pub const fn is_nil(self: &Self) -> bool { /* ... */ }
    

    Tests if the UUID is nil (all zeros).

  • pub const fn is_max(self: &Self) -> bool { /* ... */ }
    

    Tests if the UUID is max (all ones).

  • pub const fn encode_buffer() -> [u8; 45] { /* ... */ }
    

    A buffer that can be used for encode_... calls, that is

  • pub const fn get_timestamp(self: &Self) -> Option<Timestamp> { /* ... */ }
    

    If the UUID is the correct version (v1, v6, or v7) this will return

  • pub const fn get_node_id(self: &Self) -> Option<[u8; 6]> { /* ... */ }
    

    If the UUID is the correct version (v1, or v6) this will return the

Trait Implementations
  • Any

    • fn type_id(self: &Self) -> TypeId { /* ... */ }
      
  • Arbitrary

    • fn arbitrary(u: &mut Unstructured<''_>) -> arbitrary::Result<Self> { /* ... */ }
      
    • fn size_hint(_: usize) -> (usize, Option<usize>) { /* ... */ }
      
  • AsRef

    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
    • fn as_ref(self: &Self) -> &Uuid { /* ... */ }
      
    • fn as_ref(self: &Self) -> &[u8] { /* ... */ }
      
  • Borrow

    • fn borrow(self: &Self) -> &T { /* ... */ }
      
    • fn borrow(self: &Self) -> &Uuid { /* ... */ }
      
    • fn borrow(self: &Self) -> &Uuid { /* ... */ }
      
    • fn borrow(self: &Self) -> &Uuid { /* ... */ }
      
    • fn borrow(self: &Self) -> &Uuid { /* ... */ }
      
  • BorrowMut

    • fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
      
  • BorshDeserialize

    • fn deserialize_reader<__R: borsh::io::Read>(reader: &mut __R) -> ::core::result::Result<Self, borsh::io::Error> { /* ... */ }
      
  • BorshSerialize

    • fn serialize<__W: borsh::io::Write>(self: &Self, writer: &mut __W) -> ::core::result::Result<(), borsh::io::Error> { /* ... */ }
      
  • Clone

    • fn clone(self: &Self) -> Uuid { /* ... */ }
      
  • CloneToUninit

    • unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
      
  • Copy

  • Debug

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Default

    • fn default() -> Self { /* ... */ }
      
  • Deserialize

    • fn deserialize<D: Deserializer<''de>>(deserializer: D) -> Result<Self, <D as >::Error> { /* ... */ }
      
  • DeserializeOwned

  • Display

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Eq

  • Freeze

  • From

    • fn from(t: T) -> T { /* ... */ }
      

      Returns the argument unchanged.

    • fn from(non_nil: NonNilUuid) -> Self { /* ... */ }
      

      Converts a [NonNilUuid] back into a [Uuid].

    • fn from(uuid: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Hyphenated) -> Self { /* ... */ }
      
    • fn from(f: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Simple) -> Self { /* ... */ }
      
    • fn from(f: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Urn) -> Self { /* ... */ }
      
    • fn from(f: Uuid) -> Self { /* ... */ }
      
    • fn from(f: Braced) -> Self { /* ... */ }
      
    • fn from(value: Uuid) -> Self { /* ... */ }
      
  • FromStr

    • fn from_str(uuid_str: &str) -> Result<Self, <Self as >::Err> { /* ... */ }
      
  • Hash

    • fn hash<H: Hasher>(self: &Self, state: &mut H) { /* ... */ }
      
  • Into

    • fn into(self: Self) -> U { /* ... */ }
      
      Calls U::from(self).
  • LowerHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Ord

    • fn cmp(self: &Self, other: &Uuid) -> $crate::cmp::Ordering { /* ... */ }
      
  • PartialEq

    • fn eq(self: &Self, other: &Uuid) -> bool { /* ... */ }
      
    • fn eq(self: &Self, other: &NonNilUuid) -> bool { /* ... */ }
      
    • fn eq(self: &Self, other: &Uuid) -> bool { /* ... */ }
      
  • PartialOrd

    • fn partial_cmp(self: &Self, other: &Uuid) -> $crate::option::Option<$crate::cmp::Ordering> { /* ... */ }
      
  • RefUnwindSafe

  • Same

  • Send

  • SendSyncUnwindSafe

  • Serialize

    • fn erased_serialize(self: &Self, serializer: &mut dyn Serializer) -> Result<Ok, Error> { /* ... */ }
      
    • fn serialize<S: Serializer>(self: &Self, serializer: S) -> Result<<S as >::Ok, <S as >::Error> { /* ... */ }
      
  • StructuralPartialEq

  • Sync

  • ToOwned

    • fn to_owned(self: &Self) -> T { /* ... */ }
      
    • fn clone_into(self: &Self, target: &mut T) { /* ... */ }
      
  • ToString

    • fn to_string(self: &Self) -> String { /* ... */ }
      
  • TryFrom

    • fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
      
    • fn try_from(uuid: Uuid) -> Result<Self, <Self as >::Error> { /* ... */ }
      

      Attempts to convert a [Uuid] into a [NonNilUuid].

    • fn try_from(uuid_str: &str) -> Result<Self, <Self as >::Error> { /* ... */ }
      
    • fn try_from(uuid_str: String) -> Result<Self, <Self as >::Error> { /* ... */ }
      
    • fn try_from(value: std::vec::Vec<u8>) -> Result<Self, <Self as >::Error> { /* ... */ }
      
  • TryInto

    • fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
      
  • Unpin

  • UnwindSafe

  • UpperHex

    • fn fmt(self: &Self, f: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
      
  • Value

    • fn serialize(self: &Self, _: &slog::Record<''_>, key: slog::Key, serializer: &mut dyn slog::Serializer) -> Result<(), slog::Error> { /* ... */ }
      

Macros

Macro uuid

Attributes:

  • Other("#[<cfg_trace>(not(feature = \"macro-diagnostics\"))]")
  • MacroExport

Parse Uuids from string literals at compile time.

Usage

This macro transforms the string literal representation of a Uuid into the bytes representation, raising a compilation error if it cannot properly be parsed.

Examples

Setting a global constant:

# use uuid::{uuid, Uuid};
pub const SCHEMA_ATTR_CLASS: Uuid = uuid!("00000000-0000-0000-0000-ffff00000000");
pub const SCHEMA_ATTR_UUID: Uuid = uuid!("00000000-0000-0000-0000-ffff00000001");
pub const SCHEMA_ATTR_NAME: Uuid = uuid!("00000000-0000-0000-0000-ffff00000002");

Defining a local variable:

# use uuid::uuid;
let uuid = uuid!("urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4");

Using a const variable:

# use uuid::uuid;
const UUID_STR: &str = "12345678-1234-5678-1234-567812345678";
let UUID = uuid!(UUID_STR);

Compilation Failures

Invalid UUIDs are rejected:

# use uuid::uuid;
let uuid = uuid!("F9168C5E-ZEB2-4FAA-B6BF-329BF39FA1E4");

Enable the feature macro-diagnostics to see the error messages below.

Provides the following compilation error:

error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-fA-F-], found Z at 9
    |
    |     let id = uuid!("F9168C5E-ZEB2-4FAA-B6BF-329BF39FA1E4");
    |                              ^
pub macro_rules! uuid {
    /* macro_rules! uuid {
    ($uuid:expr) => { ... };
} */
}

Re-exports

Re-export NoContext

pub use timestamp::context::NoContext;

Re-export ClockSequence

pub use timestamp::ClockSequence;

Re-export Timestamp

pub use timestamp::Timestamp;

Re-export Context

Attributes:

  • Other("#[<cfg_trace>(any(feature = \"v1\", feature = \"v6\"))]")
pub use timestamp::context::Context;

Re-export ContextV7

Attributes:

  • Other("#[<cfg_trace>(feature = \"v7\")]")
pub use timestamp::context::ContextV7;

Re-export Builder

pub use crate::builder::Builder;

Re-export Error

pub use crate::error::Error;

Re-export NonNilUuid

pub use crate::non_nil::NonNilUuid;