cargo : uuid @ 1.23.1
README.md
90 lines · markdown
# `uuid`[](https://crates.io/crates/uuid)[](https://github.com/uuid-rs/uuid/actions/workflows/ci.yml)Here's an example of a UUID:```text67e55044-10b1-426f-9247-bb680e5fe0c8```A UUID is a unique 128-bit value, stored as 16 octets, and regularlyformatted as a hex string in five groups. UUIDs are used to assign uniqueidentifiers to entities without requiring a central allocating authority.They are particularly useful in distributed systems, though can be used indisparate areas, such as databases and network protocols. Typically a UUIDis 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 allpractical purposes, it can be assumed that an unintentional collision wouldbe extremely unlikely.## Getting startedAdd the following to your `Cargo.toml`:```toml[dependencies.uuid]version = "1.23.1"# Lets you generate random UUIDsfeatures = [ "v4",]```When you want a UUID, you can generate one:```rustuse uuid::Uuid;let id = Uuid::new_v4();```If you have a UUID value, you can use its string literal form inline:```rustuse uuid::{uuid, Uuid};const ID: Uuid = uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8");```You can also parse UUIDs without needing any crate features:```rustuse 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`](https://github.com/nugine/uuid-simd)library.For more details on using `uuid`, [see the library documentation](https://docs.rs/uuid/1.23.1/uuid).## References* [`uuid` library docs](https://docs.rs/uuid/1.23.1/uuid).* [Wikipedia: Universally Unique Identifier](http://en.wikipedia.org/wiki/Universally_unique_identifier).* [RFC 9562: Universally Unique IDentifiers (UUID)](https://www.ietf.org/rfc/rfc9562.html).---# LicenseLicensed under either of* Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)* MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)at your option.## ContributionUnless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shallbe dual licensed as above, without any additional terms or conditions.