Crate lid

source ·
Expand description

Fast and customizable ID generator.

§Quick Start

The easiest way to use LID is by using the easy feature and using [generate_distributed] or [generate_random]. These use a static LID instance backed by a [Mutex].

You may also change the alphabet used by switching up the feature flags. The available features are: base32, base36, and base62. NOTE: When using base62, the default ID size will change to 20 bytes. If not using the base62 feature, the default ID size will be 28 bytes.

§Unsafe

By default this crate uses unsafe when converting from &u8 to String, this is safe due to the alphabets always being UTF8. If you would like, you can change [generate] to return a Result<String, FromUtf8Error> by enabling the no-unsafe feature.

§Customization

You can always customize your ID size with const generics:

use lid::LID;

let mut lid = LID::<12, 8>::default(); // This will give you a 20 byte ID.
println!("{:?}", lid.generate());

You can also customize the ‘randomness’ of the IDs generated by changing the MIN_INCREMENT and MAX_INCREMENT generic values.

use lid::LID;

let mut lid = LID::<6, 9, 1000, 1_000_000>::default();
println!("{:?}", lid.generate());

Modules§

Structs§

  • The combined total of PREFIX_LENGTH and SEQUENCE_LENGTH is the length of the ID. By default, this is 28 bytes.

Constants§