Find a file
2021-09-26 21:09:24 +10:00
.cargo add const uuid::from_uuid_bytes 2018-05-05 00:25:39 +08:00
.github Update to getrandom:0.2.0 2020-12-20 23:45:29 -05:00
benches refactor error types and mod layout 2019-10-02 14:05:30 +10:00
src enable v3,v4,v5 on all but wasm32-unknown-unknown 2021-09-20 13:25:02 +02:00
.gitignore ignore vim files 2019-03-01 01:14:27 -08:00
.rustfmt.toml add .rustfmt.toml to allow certain amount of format standard 2018-04-26 20:32:00 -07:00
.travis.yml remove fmt from travis 2020-09-02 17:12:22 -07:00
bors.toml remove appveyoir from bors 2020-08-31 15:09:10 -07:00
Cargo.toml prepare for 0.8.2 release 2021-01-08 11:45:38 +10:00
CODE_OF_CONDUCT.md update code of conduct 2018-08-08 17:36:46 -07:00
CODEOWNERS fix(bors): actually prevent changes to bors without needing review 2018-02-14 15:27:07 -08:00
CONTRIBUTING.md Update minimum rust version 2018-10-05 02:28:31 +05:30
COPYRIGHT Add COPYRIGHT file and add license headers to all rs files 2018-05-11 16:51:06 -07:00
LICENSE-APACHE Organise code and add Travis CI config 2014-07-30 23:14:56 +01:00
LICENSE-MIT copyright added to licence 2018-02-16 17:06:17 +05:30
README.md prepare for 0.8.2 release 2021-01-08 11:45:38 +10:00
README.tpl Update to getrandom:0.2.0 2020-12-20 23:45:29 -05:00

uuid

Latest Version Join the chat at https://gitter.im/uuid-rs/Lobby Minimum rustc version Build Status Build Status Average time to resolve an issue Percentage of issues still open FOSSA Status


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.

Dependencies

By default, this crate depends on nothing but std and cannot generate Uuids. You need to enable the following Cargo features to enable various pieces of functionality:

  • v1 - adds the Uuid::new_v1 function and the ability to create a V1 using an implementation of uuid::v1::ClockSequence (usually uuid::v1::Context) and a timestamp from time::timespec.
  • v3 - adds the Uuid::new_v3 function and the ability to create a V3 UUID based on the MD5 hash of some data.
  • v4 - adds the Uuid::new_v4 function and the ability to randomly generate a Uuid.
  • v5 - adds the Uuid::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 a Uuid using the serde crate.

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

  • stdweb - enables support for OsRng on wasm32-unknown-unknown via stdweb combined with cargo-web
  • wasm-bindgen - wasm-bindgen enables support for OsRng on wasm32-unknown-unknown via wasm-bindgen

By default, uuid can be depended on with:

[dependencies]
uuid = "0.8"

To activate various features, use syntax like:

[dependencies]
uuid = { version = "0.8", features = ["serde", "v4"] }

You can disable default features with:

[dependencies]
uuid = { version = "0.8", default-features = false }

Examples

To parse a UUID given in the simple format and print it as a urn:

use uuid::Uuid;

fn main() -> Result<(), uuid::Error> {
    let my_uuid =
        Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8")?;
    println!("{}", my_uuid.to_urn());
    Ok(())
}

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);
    Ok(())
}

Strings

Examples of string representations:

  • simple: 936DA01F9ABD4d9d80C702AF85C822A8
  • hyphenated: 550e8400-e29b-41d4-a716-446655440000
  • urn: urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4

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.