ids/cuid

A module for generating CUIDs (Collision-resistant Unique Identifiers). The implementation requires a counter, so an actor is used to keep track of that state. This means before generating a CUID, an actor needs to be started and all work is done via a channel.

Slugs are also supported.

Types

The messages handled by the actor.

The actor shouldn’t be called directly so this type is opaque.

pub opaque type Message

The internal state of the actor.

The state keeps track of a counter and a fingerprint. Both are used when generating a CUID.

pub opaque type State

Functions

pub fn generate(channel: Subject(Message)) -> String

Generates a CUID using the given channel.

Usage

import ids/cuid

let assert Ok(channel) = cuid.start()

let id: String = cuid.generate(channel)

let slug: String = cuid.slug(channel)
pub fn is_cuid(id: String) -> Bool

Checks if a string is a CUID.

pub fn is_slug(slug: String) -> Bool

Checks if a string is a slug.

pub fn slug(channel: Subject(Message)) -> String

Generates a slug using the given channel.

pub fn start() -> Result(Subject(Message), StartError)

Starts a CUID generator.

Search Document