uuid

Latest Version Minimum rustc version Continuous integration


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 they 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

To get started with generating random UUIDs, add this to your Cargo.toml:

toml [dependencies.uuid] version = "1" features = ["v4", "fast-rng"]

and then call Uuid::new_v4 in your code:

```rust use uuid::Uuid;

let myuuid = Uuid::newv4(); ```

You can also parse UUIDs without needing any crate features:

```rust use uuid::{Uuid, Version};

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

asserteq!(Some(Version::Random), myuuid.get_version()); ```

You can parse UUIDs at compile time instead of at runtime.

If you add the macro-diagnostics feature then you can see much better error messages.

```rust

[macro_use]

extern crate uuid;

let my_uuid = uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8")?;

asserteq!(Some(Version::Random), myuuid.get_version()); ```

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:

You need to enable one of the following Cargo features together with the v4 feature if you're targeting wasm32-unknown-unknown target:

Alternatively, you can provide a custom getrandom implementation yourself via getrandom::register_custom_getrandom.

Unstable features

Some features are unstable. They may be incomplete or depend on other unstable libraries. These include:

Unstable features may break between minor releases.

To allow unstable features, you'll need to enable the Cargo feature as normal, but also pass an additional flag through your environment to opt-in to unstable uuid features:

RUSTFLAGS="--cfg uuid_unstable"

Minimum Supported Rust Version (MSRV)

The minimum supported Rust version for uuid is documented in CI. It may be bumped in minor releases as necessary.

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.