gxid

Types

Message handled by the generator started with start

pub opaque type Message

A globally unique, sortable 12-byte identifier

This is an opaque type to ensure its RO nature

pub opaque type XID

Values

pub fn compare(a: XID, b: XID) -> order.Order

Orders two XIDs by creation time, then machine, process and counter

pub fn counter(xid: XID) -> Int

Returns the counter from XID type

pub fn from_bit_array(bit_xid: BitArray) -> Result(XID, Nil)

Builds an XID from its 12-byte binary representation

pub fn generate(channel: process.Subject(Message)) -> XID

Deprecated: Use gxid.new, which needs no process

Generates an XID through a process started with start

pub fn machine_id(xid: XID) -> Int

Returns machine id from XID type

pub fn new() -> XID

Generates a new XID

Safe to call from any number of processes at once: no process needs to be started first.

Usage

import gxid.{type XID}

let xid: XID = gxid.new()
pub fn parse(str_xid: String) -> Result(XID, Nil)

Parses an XID from its 20-character string representation

Usage

import gxid

let assert Ok(xid) = gxid.parse("9m4e2mr0ui3e8a215n4g")
pub fn pid(xid: XID) -> Int

Returns PID from XID type

pub fn random_number(xid: XID) -> Int

Deprecated: Use gxid.counter

Returns the counter from XID type

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

Deprecated: Use gxid.new, which needs no process

Starts a process generating XIDs

pub fn string(xid: XID) -> String

Returns xid string representation from XID type

pub fn time(xid: XID) -> Int

Returns the creation time, in seconds since the Unix epoch

pub fn to_bit_array(xid: XID) -> BitArray

Returns the 12-byte binary representation of an XID

pub fn to_xid(bit_xid: BitArray) -> XID

Deprecated: Use gxid.from_bit_array, which does not crash on invalid input

Builds an XID from its 12-byte binary representation

✨ Search Document