Crate uuid[−][src]
Generate and parse UUIDs.
Provides support for Universally Unique Identifiers (UUIDs). A UUID is a unique 128-bit number, stored as 16 octets. 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.
Dependencies
By default, this crate depends on nothing but std
and cannot generate
Uuid
s. You need to enable the following Cargo features to enable
various pieces of functionality:
v1
- adds theUuid::new_v1
function and the ability to create a V1 using an implementation ofUuidV1ClockSequence
(usuallyUuidV1Context
) and a timestamp fromtime::timespec
.v3
- adds theUuid::new_v3
function and the ability to create a V3 UUID based on the MD5 hash of some data.v4
- adds theUuid::new_v4
function and the ability to randomly generate aUuid
.v5
- adds theUuid::new_v5
function and the ability to create a V5 UUID based on the SHA1 hash of some data.serde
- adds the ability to serialize and deserialize aUuid
using theserde
crate.
By default, uuid
can be depended on with:
[dependencies]
uuid = "0.6"
To activate various features, use syntax like:
[dependencies]
uuid = { version = "0.6", features = ["serde", "v4"] }
You can disable default features with:
[dependencies]
uuid = { version = "0.6", default-features = false }
Examples
To parse a UUID given in the simple format and print it as a urn:
use uuid::Uuid; fn main() { let my_uuid = Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap(); println!("{}", my_uuid.urn()); }
To 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() { let my_uuid = Uuid::new_v4(); println!("{}", my_uuid); }
Strings
Examples of string representations:
- simple:
936DA01F9ABD4d9d80C702AF85C822A8
- hyphenated:
550e8400-e29b-41d4-a716-446655440000
- urn:
urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4
References
Modules
prelude |
The |
Structs
Hyphenated |
An adaptor for formatting a |
Simple |
An adaptor for formatting a |
Urn |
An adaptor for formatting a |
Uuid |
A Universally Unique Identifier (UUID). |
UuidV1Context |
A thread-safe, stateful context for the v1 generator to help ensure process-wide uniqueness. |
Enums
ParseError |
Error details for string parsing failures. |
UuidVariant |
The reserved variants of UUIDs. |
UuidVersion |
The version of the UUID, denoting the generating algorithm. |
Constants
NAMESPACE_DNS |
A UUID of the namespace of fully-qualified domain names |
NAMESPACE_OID |
A UUID of the namespace of ISO OIDs |
NAMESPACE_URL |
A UUID of the namespace of URLs |
NAMESPACE_X500 |
A UUID of the namespace of X.500 DNs (in DER or a text output format) |
Traits
UuidV1ClockSequence |
A trait that abstracts over generation of Uuid v1 "Clock Sequence" values. |
Type Definitions
UuidBytes |
A 128-bit (16 byte) buffer containing the ID. |