3 releases

0.1.2 Aug 8, 2023
0.1.1 Aug 2, 2023
0.1.0 Jan 22, 2023

#903 in Network programming

Download history 1972/week @ 2023-12-17 1800/week @ 2023-12-24 1907/week @ 2023-12-31 2315/week @ 2024-01-07 1999/week @ 2024-01-14 1973/week @ 2024-01-21 2712/week @ 2024-01-28 2557/week @ 2024-02-04 2746/week @ 2024-02-11 3880/week @ 2024-02-18 3141/week @ 2024-02-25 3158/week @ 2024-03-03 3204/week @ 2024-03-10 3675/week @ 2024-03-17 2885/week @ 2024-03-24 2695/week @ 2024-03-31

12,759 downloads per month
Used in 18 crates (4 directly)

MIT license

27KB
303 lines

Cuid2

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).

Usage

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
y3cfw1hafbtezzflns334sb2

Dependencies

~2MB
~31K SLoC