Code Monkey home page Code Monkey logo

uuid's Introduction

uuid

Build Status Latest Version Join the chat at https://gitter.im/uuid-rs/Lobby

A Rust library to 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.

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
uuid = "0.5"

and this to your crate root:

extern crate uuid;

Examples

To parse a simple UUID, then print the version and urn string format:

extern crate uuid;
use uuid::Uuid;

fn main() {
    let my_uuid = Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap();
    println!("Parsed a version {} UUID.", my_uuid.get_version_num());
    println!("{}", my_uuid);
}

The library supports 5 versions of UUID:

Name Version
Mac Version 1: MAC address
Dce Version 2: DCE Security
Md5 Version 3: MD5 hash
Random Version 4: Random
Sha1 Version 5: SHA-1 hash

To create a new random (V4) UUID and print it out in hexadecimal form, first you'll need to change how you depend on uuid:

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

Next, you'll write:

extern crate uuid;
use uuid::Uuid;

fn main() {
    let my_uuid = Uuid::new_v4();
    println!("{}", my_uuid);
}

To create a new sha1-hash based (V5) UUID and print it out in hexadecimal form, you'll also need to change how you depend on uuid:

[dependencies]
uuid = { version = "0.5", features = ["v5"] }

Next, you'll write:

extern crate uuid;
use uuid::Uuid;

fn main() {
    let my_uuid = Uuid::new_v5(&uuid::NAMESPACE_DNS, "foo");
    println!("{}", my_uuid);
}

References

Wikipedia: Universally Unique Identifier

uuid's People

Contributors

agrover avatar alexcrichton avatar aochagavia avatar bors avatar bors[bot] avatar brendanzab avatar brson avatar chills42 avatar erickt avatar errordeveloper avatar fabricedesre avatar flaper87 avatar frewsxcv avatar heroesgrave avatar huonw avatar kinggoesgaming avatar kodraus avatar kraai avatar kroisse avatar liigo avatar mdsteele avatar mranno avatar pcwalton avatar richo avatar rrichardson avatar rushmorem avatar sfackler avatar sinistersnare avatar steveklabnik avatar stuarth avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.