std/identifier/identifier

std/identifier/src/identifier.trb

Identifier: what Uuid and Ulid have in common (docs/design/URI.md section 12).

trait Identifier

trait Identifier with Show, Equals, Hash, Compare, TryFrom<String, IdentifierError>

What every identifier can do: it is 128 bits, shown as text, read back from it, compared bytewise and usable as the key of a Map or an element of a Set. The failure of reading is the one IdentifierError of the package, so a function generic over Identifier needs no second type argument.

Examples

fn leadOf<Value: Identifier>(identifier: Value): UInt8 {
    identifier.bytes().first() ?? 0
}

fn bytes

fn bytes(): List<UInt8>

The identifier as its sixteen bytes, most significant first.