No description
Find a file
2022-02-12 12:14:29 -05:00
.github/workflows Create ci.yml 2022-02-12 12:02:54 -05:00
src inline docs 2022-02-12 11:10:13 -05:00
tests create tests 2022-02-10 11:16:54 -05:00
.gitignore init package with existing source 2022-02-10 11:16:17 -05:00
CHANGELOG.md put it back the way it was 2022-02-12 12:14:29 -05:00
LICENSE.md repo matter 2022-02-10 11:20:39 -05:00
README.md document surface area 2022-02-10 15:40:12 -05:00
uuid4.nimble put it back the way it was 2022-02-12 12:14:29 -05:00

uuid4

A UUID module in pure Nim.

Installation

nimble install uuid4

Usage

import uuid4

let u1 = uuid4()  # a version-4 (random) UUID
echo u1           # print the stringified version of the UUID

let u2 = initUuid("b80b3380-a167-437b-9d64-6cb574e3aae7")
echo u2.bytes[0]    # print the first byte of this UUID
echo u2.bytes[15]   # print the last byte of this UUID
echo u2.version     # this happens to be a version-4 UUID
echo u2.variant     # it's a RFC-4122 UUID

let u3 = initUuid(u1.bytes)   # make another, equivalent UUID
echo u3 == u1                 # true
var u4: Uuid
echo u4.isNil                 # true

Full API

type
  Uuid*        # an opaque object
  UuidVariant* # a {.pure.} enum of
               # ApolloNcs, Rfc4122, ReservedMicrosoft, ReservedFuture

proc uuid4*(): Uuid

proc isNil*(self: Uuid): bool

proc hash*(self: Uuid): Hash
proc `==`*(uuid1, uuid2: Uuid): bool
proc `$`*(self: Uuid): string

proc bytes*(self: Uuid): array[16, uint8]

proc initUuid*(uuidStr: string): Uuid
proc initUuid*(uuidBytes: array[16, uint8]): Uuid

proc variant*(self: Uuid): UuidVariant
proc version*(self: Uuid): int

Contributing

Contributions are welcome, especially adding more surface area from the Python uuid module. Feel free to open a PR.