#id #counter #constructor #cuid

bin+lib cuid2

An implementation of the CUID2 protocol in rust

3 releases

0.1.2 Aug 8, 2023
0.1.1 Aug 2, 2023
0.1.0 Jan 22, 2023
Download history 1790/week @ 2023-06-06 2249/week @ 2023-06-13 1867/week @ 2023-06-20 1472/week @ 2023-06-27 2083/week @ 2023-07-04 1833/week @ 2023-07-11 2028/week @ 2023-07-18 2192/week @ 2023-07-25 2548/week @ 2023-08-01 3038/week @ 2023-08-08 4393/week @ 2023-08-15 5278/week @ 2023-08-22 5560/week @ 2023-08-29 6052/week @ 2023-09-05 6365/week @ 2023-09-12 7836/week @ 2023-09-19

26,569 downloads per month
Used in 13 crates (3 directly)

MIT license

303 lines


Build Status Crates.io docs.rs

Secure, collision-resistant ids optimized for horizontal scaling and performance.

This is a Rust implementation of the CUID2 algorithm, defined by its reference implementation here.

Please see that repository for a discussion of the benefits of CUIDs, as well as for the improvements in CUID2 over the original CUID algorithm (which is also implemented in Rust here).


The simplest usage is to use the create_id() function to create an ID:

use cuid2;

let id = cuid2::create_id();

assert_eq!(24, id.len());

A cuid() alias is provided to make this more of a drop-in replacement for the v1 cuid package:

use cuid2::cuid;

let id = cuid();

assert_eq!(24, id.len());

If you would like to customize aspects of CUID production, you can create a constructor with customized properties:

use cuid2::CuidConstructor;

let constructor = CuidConstructor::new().with_length(32);

let id = constructor.create_id();

assert_eq!(32, id.len());

If installed with cargo install, this package also provides a cuid2 binary, which generates a CUID on the command line. It can be used like:

> cuid2


~30K SLoC