persistent_enums
Define enums which values preserve their binary representation upon inserting or reordering
Summary
| Latest Version | Unknown |
|---|---|
| License | MIT |
| CI Status | Failing |
| Downloads | 0 |
| Last Indexed | 2026-07-21 05:24 |
Tags
Installation
nimble install persistent_enums
choosenim install persistent_enums
git clone https://github.com/yglukhov/persistent_enums
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| persistent_enums | ✓ | ✓ | ✓ | - | - | - | - | - | - | - |
Source
| Repository | https://github.com/yglukhov/persistent_enums |
|---|---|
| Homepage | https://github.com/yglukhov/persistent_enums |
| Registry Source | nimble_official |
README
persistent_enums 
Define enums which values preserve their binary representation upon inserting or reordering
# Imagine you have the following enum
type MyEnum* {.persistent.} = enum
myFirstValue = 0
mySecondValue
# You may store enum value in binary form to somewhere:
var serializedVal = mySecondValue
writeInt16ToSomewhere(cast[ptr int16](addr serializedVal))
# Then next version of your app may add more values to the enum, e.g.
type MyEnum* {.persistent.} = enum
myFirstValue = 0
myNewlyInsertedValue
mySecondValue
# Reading old binary value
var deserializedVal : MyEnum
readInt16FromSomewhere(cast[ptr int16](addr deserializedVal)
# With normal enums you would end up with deserializedVal == myNewlyInsertedValue
# But with persistent enum the following assertion will hold
assert(deserializedVal == mySecondValue)
Under the hood
There is no runtime cost. Binary represenations of enum values are actually equal to crc16 of their string representation, unless the value is explicitly set in enum definition. In case of collision a compile time error will be raised.