XU XUv0.8.8
中文

API

#id

import: #id

counts: 5 fns, 1 methods, 1 types, 0 consts, 0 ifaces

Sortable identifiers for messages / files / sessions. ULID (Crockford base32, 26 chars): 48-bit ms timestamp + 80-bit random. UUIDv7 (RFC 9562): 48-bit unix ms + version/variant + 62-bit random, canonical 8-4-4-4-12 lowercase hex. Monotonic ULID: same-millisecond ids increment the random field so lexicographic order matches issue order on one process. Xu forbids package mutable globals — keep a Monotonic generator per producer.

new_ulid

XuAPI
pub fn new_ulid() string

Purpose

new_ulid returns a 26-char Crockford ULID for the current wall clock. Throws on failure.

Parameters

none

Returns

string — result string

struct Monotonic

XuAPI
pub struct Monotonic {

}

Purpose

Monotonic keeps the last ULID so same-ms ids stay ordered.

Parameters

none

new_monotonic

XuAPI
pub fn new_monotonic() Monotonic

Purpose

Construct monotonic.

Parameters

none

Returns

Monotonic — a value of this type

(&mut Monotonic) next

XuAPI
pub fn (m &mut Monotonic) next() string

Purpose

next returns a ULID ≥ the previous one from this generator (process-local). Throws on failure.

Parameters

m &mut Monotonic
receiver &mut Monotonic (exclusive borrow)

Returns

string — result string

ulid_time_ms

XuAPI
pub fn ulid_time_ms(s string) int

Purpose

ulid_time_ms extracts the 48-bit timestamp from a 26-char ULID. Returns -1 on bad input.

Parameters

s string
source string (string)

Returns

int — a value of this type

new_uuid_v7

XuAPI
pub fn new_uuid_v7() string

Purpose

new_uuid_v7 returns a canonical UUIDv7 (8-4-4-4-12 lowercase hex). Throws on failure.

Parameters

none

Returns

string — result string

uuid_v7_time_ms

XuAPI
pub fn uuid_v7_time_ms(s string) int

Purpose

uuid_v7_time_ms extracts unix ms from a UUIDv7 string. -1 if invalid.

Parameters

s string
source string (string)

Returns

int — a value of this type