variant

Variant type and type matching

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:24

Tags

Installation

nimble install variant
choosenim install variant
git clone https://github.com/yglukhov/variant.git

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
variant - - - - - - -

Source

Repository https://github.com/yglukhov/variant.git
Homepage https://github.com/yglukhov/variant
Registry Source nimble_official

README

variant Build Status nimble

Variant type and type matching for Nim

import variant

var v = newVariant(5)
assert v.ofType(int)
assert v.get(int) == 5

v = newVariant(3.0)
assert v.ofType(float)
assert v.get(float) == 3.0

v = newVariant(@[1, 2, 3])
assert v.ofType(seq[int])
assert v.get(seq[int])[1] == 2

Matching:

var v = newVariant(@[1, 2, 3])
assert v.ofType(seq[int])
variantMatch case v as u
of int:
    echo "u is int: ", u
of seq[int]:
    echo "u is seq[int]: ", u
else:
    echo "dont know what v is"

Will output:

u is seq[int]: @[1, 2, 3]