commit | cf5d9caf4f69ac67d0dfd7a0ff28873e62abf5f9 | [log] [tgz] |
---|---|---|
author | James Farrell <[email protected]> | Wed Sep 18 20:37:08 2024 +0000 |
committer | James Farrell <[email protected]> | Wed Sep 18 20:37:08 2024 +0000 |
tree | e1860538319de6f24e8694c984ceb7b6247ee2a1 | |
parent | 193a27b5e2a5c60816acd08ce287905478f7e399 [diff] |
Migrate 26 crates to monorepo tokio-util tower tower-layer tower-service tracing tracing-attributes tracing-core tracing-subscriber try-lock tungstenite twox-hash ucd-trie unicode-bidi unicode-normalization unicode-segmentation unicode-width unsafe-libyaml userfaultfd utf-8 uuid weak-table webpki which winnow x509-cert xml-rs Bug: http://b/339424309 Test: treehugger Change-Id: I1be260ff837571e8d1460a2eab8f1dfefbc9fe5f
uuid
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.
Add the following to your Cargo.toml
:
[dependencies.uuid] version = "1.7.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.
uuid
library docs.Licensed under either of
at your option.
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.