ids/cuid

Generating a cuid. 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.

Usage

import ids/cuid

assert Ok(channel) = cuid.start()

let id = cuid.gen(channel)

let slug = cuid.slug(channel)

Types

Message

The messages handled by the actor.

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

pub opaque type Message

State

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

gen

pub fn gen(channel: Sender(Message)) -> String

Generates a cuid using the given channel.

is_cuid

pub fn is_cuid(id: String) -> Bool

Checks if a string is a cuid.

is_slug

pub fn is_slug(slug: String) -> Bool

Checks if a string is a slug.

slug

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

Generates a slug using the given channel.

start

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

Starts a cuid generator.