69 releases (22 stable)

1.11.0 Oct 16, 2024
1.10.0 Jul 9, 2024
1.9.1 Jun 24, 2024
1.8.0 Mar 19, 2024
0.1.0 Nov 27, 2014

#1 in Parser implementations

Download history 2077761/week @ 2024-08-04 2166395/week @ 2024-08-11 2178417/week @ 2024-08-18 2197440/week @ 2024-08-25 2167802/week @ 2024-09-01 2216488/week @ 2024-09-08 1998634/week @ 2024-09-15 2196196/week @ 2024-09-22 2202714/week @ 2024-09-29 2296255/week @ 2024-10-06 2434001/week @ 2024-10-13 2496048/week @ 2024-10-20 2320092/week @ 2024-10-27 2352322/week @ 2024-11-03 2404996/week @ 2024-11-10 2355677/week @ 2024-11-17

9,560,249 downloads per month
Used in 14,983 crates (5,065 directly)

Apache-2.0 OR MIT

245KB
4K SLoC

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.11.0"
features = [
    "v4",                # Lets you generate random UUIDs
    "fast-rng",          # Use a faster (but still sufficiently random) RNG
    "macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
]

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.

FOSSA Status

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.

Dependencies

~0–1.1MB
~19K SLoC