#id #number #type #unique

no-std uid

A crate for the creation of unique IDs

9 releases

0.1.7 Dec 29, 2021
0.1.6 Dec 24, 2021
0.1.5 Jan 2, 2021
0.1.4 Dec 26, 2018
0.0.0 Oct 22, 2018

#145 in Concurrency

Download history 289/week @ 2023-06-03 479/week @ 2023-06-10 425/week @ 2023-06-17 172/week @ 2023-06-24 322/week @ 2023-07-01 292/week @ 2023-07-08 379/week @ 2023-07-15 285/week @ 2023-07-22 216/week @ 2023-07-29 456/week @ 2023-08-05 340/week @ 2023-08-12 530/week @ 2023-08-19 315/week @ 2023-08-26 607/week @ 2023-09-02 769/week @ 2023-09-09 412/week @ 2023-09-16

2,139 downloads per month
Used in 8 crates (7 directly)


168 lines

pipeline coverage crates.io Docs rustc


uid (short for unique identifiers) is a crate for creating unique IDs for usage in a Rust program. IDs can have many purposes in programs, but this crate's IDs are mostly useful for identification tasks. For example, consider having some form of simple in-memory database (in the form of a HashMap or something more sophisticated). IDs as created by this crate make for perfect primary keys.

Said IDs have a couple properties that, depending on the context, are useful to have:

  1. IDs are lightweight and ultimately just a number with some compile time magic (and a small creation cost) attached to them.
  2. Created IDs are guaranteed to be unique. That is, when created at runtime (deserialization is not supported for obvious reasons), two newly crated IDs are guaranteed to never be the same.
  3. They are fully thread safe. That is, uniqueness is guaranteed even among different threads.
  4. IDs are immutable. Once created, an ID can (potentially) be copied, hashed, compared, and more, but it cannot be changed.
  5. IDs can form name (or rather type) spaces. That is, an ID can be parametrized by an arbitrary (potentially private) type and only IDs that are parametrized by the same type can interact (i.e., be compared etc.).

No runtime deps