9 unstable releases

0.5.0 Aug 10, 2023
0.4.1 Oct 4, 2022
0.3.2 Dec 7, 2021
0.3.0 Dec 29, 2020
0.1.0 Apr 7, 2018

#104 in Data structures

Download history 22105/week @ 2023-12-11 22740/week @ 2023-12-18 13062/week @ 2023-12-25 19796/week @ 2024-01-01 27148/week @ 2024-01-08 28789/week @ 2024-01-15 29868/week @ 2024-01-22 31803/week @ 2024-01-29 26275/week @ 2024-02-05 24769/week @ 2024-02-12 26976/week @ 2024-02-19 31719/week @ 2024-02-26 31977/week @ 2024-03-04 30476/week @ 2024-03-11 28941/week @ 2024-03-18 30928/week @ 2024-03-25

123,432 downloads per month
Used in 113 crates (9 directly)

Apache-2.0

11KB
156 lines

NUID

License Apache 2

A highly performant unique identifier generator.

Installation

In Cargo.toml:

[dependencies]
nuid = "0.5"

Basic Usage

// Utilize the global locked instance
nuid := nuid::next();

// Create an instance, these are not locked.
n := nuid::NUID::new();
nuid = n.next();

// Generate a new crypto/rand seeded prefix.
// Generally not needed, happens automatically.
n.randomize_prefix();

Performance

NUID needs to be very fast to generate and be truly unique, all while being entropy pool friendly. NUID uses 12 bytes of crypto generated data (entropy draining), and 10 bytes of pseudo-random sequential data that increments with a pseudo-random increment.

Total length of a NUID string is 22 bytes of base 62 ascii text, so 62^22 or 2707803647802660400290261537185326956544 possibilities.

NUID can generate identifiers as fast as 60ns, or ~16 million per second. There is an associated benchmark you can use to test performance on your own hardware.

License

Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.

Dependencies

~310KB