Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vtbassmatt/nim-uuid4
UUIDs in pure Nim
https://github.com/vtbassmatt/nim-uuid4
nim uuid
Last synced: about 2 months ago
JSON representation
UUIDs in pure Nim
- Host: GitHub
- URL: https://github.com/vtbassmatt/nim-uuid4
- Owner: vtbassmatt
- License: mit
- Created: 2022-02-10T16:18:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-12T17:18:48.000Z (almost 3 years ago)
- Last Synced: 2024-10-26T09:08:38.237Z (3 months ago)
- Topics: nim, uuid
- Language: Nim
- Homepage:
- Size: 9.77 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# uuid4
A UUID module in pure Nim.
## Installation
```
nimble install uuid4
```## Usage
```nim
import uuid4let u1 = uuid4() # a version-4 (random) UUID
echo u1 # print the stringified version of the UUIDlet 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 UUIDlet u3 = initUuid(u1.bytes) # make another, equivalent UUID
echo u3 == u1 # true
var u4: Uuid
echo u4.isNil # true
```## Full API
```nim
type
Uuid* # an opaque object
UuidVariant* # a {.pure.} enum of
# ApolloNcs, Rfc4122, ReservedMicrosoft, ReservedFutureproc uuid4*(): Uuid
proc isNil*(self: Uuid): bool
proc hash*(self: Uuid): Hash
proc `==`*(uuid1, uuid2: Uuid): bool
proc `$`*(self: Uuid): stringproc bytes*(self: Uuid): array[16, uint8]
proc initUuid*(uuidStr: string): Uuid
proc initUuid*(uuidBytes: array[16, uint8]): Uuidproc 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.