puid

A unique ID generator with 'ch_'-style prefix

2 unstable releases

0.2.0 Feb 4, 2023
0.1.0 May 2, 2022

MIT license

10KB
196 lines

puid

A unique ID generator using a given prefix with ch_-style.

The ID is a composition of:

  • Prefix.
  • Underscore character.
  • Timestamp turned into Base-36.
  • A u8 type counter.
  • The OS-assigned process identifier turned into Base-36.
  • Sequence the random characters.

Examples

Using the default random length

use puid::puid;

fn main() {
  let id = Puid::builder().prefix("foo").unwrap().build().unwrap(); // foo_l2ok01bl0yq2i2ElC7zWaCR8
}

Using custom random length

use puid::puid;

fn main() {
  let id = Puid::builder().prefix("bar").unwrap().entropy(24).build().unwrap(); // bar_l2ok1yvk1z4aOz1P7kecCTaqUGq1wgKfHGZC
}

lib.rs:

A unique ID generator using a given prefix with ch_-style.

The ID is a composition of:

  • Prefix.
  • Underscore character.
  • Timestamp turned into Base-36.
  • A u8 type counter.
  • The OS-assigned process identifier turned into Base-36.
  • Sequence the random characters.

Examples

Using the default random length

use puid::Puid;

fn main() {
    let id = Puid::builder().prefix("foo").unwrap().build().unwrap(); // foo_l2ok01bl0yq2i2ElC7zWaCR8
}

Using custom random length

use puid::Puid;

fn main() {
    let id = Puid::builder().prefix("bar").unwrap().entropy(24).build().unwrap(); // bar_l2ok1yvk1z4aOz1P7kecCTaqUGq1wgKfHGZC
}

Dependencies

~310KB