#uuid #details #generate #parse #unique-identifier

no-std uuid-rng-internal

Private implementation details of the uuid crate

7 stable releases

new 1.16.0 Mar 14, 2025
1.15.1 Feb 26, 2025
1.14.0 Feb 21, 2025
1.13.2 Feb 17, 2025
1.13.1 Feb 5, 2025

#856 in Parser implementations

Download history 423/week @ 2025-02-01 415/week @ 2025-02-08 1207/week @ 2025-02-15 2128/week @ 2025-02-22 2234/week @ 2025-03-01 2019/week @ 2025-03-08

7,690 downloads per month
Used in 3 crates (via uuid)

Apache-2.0 OR MIT

3KB

uuid

Latest Version Continuous integration

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.

Getting started

Add the following to your Cargo.toml:

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

When you want a UUID, you can generate one:

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");

You can also parse UUIDs without needing any crate features:

use uuid::{Uuid, Version};

let my_uuid = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8")?;

assert_eq!(Some(Version::Random), my_uuid.get_version());

If you'd like to parse UUIDs really fast, check out the uuid-simd library.

For more details on using uuid, see the library documentation.

References


License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Implementation details for the uuid crate.

This crate is not meant to be used directly. It allows wasm32-unknown-unknown users who aren't in a JS-enabled runtime to configure a source of randomness via getrandom:

[dependencies.uuid]
features = ["v4", "rng-getrandom"]

Dependencies

~0–5MB