8000 GitHub - holo-nim/skinsuit: utility macros mostly for object variants · GitHub
[go: up one dir, main page]

Skip to content
holo-nimPublic

About

utility macros mostly for object variants

Topics

Resources

Stars

24 stars

Watchers

1 watching

Forks

Latest commit

 

History

37 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

skinsuit

Utility macros mostly for object variants

import skinsuit

type Value {.sum, equals.} = object 
  case kind: _
  of None: discard
  of Integer, Boolean:
    _: int
  of Unsigned:
    _: uint
  of Float:
    _: float

# == for case objects generated by equals
assert Value(kind: Integer, integer: 1) == Integer(1)
assert Value(kind: Boolean, integer: 1) == Boolean(1)
assert Value(kind: Unsigned, unsigned: 1) == Unsigned(1)
assert Value(kind: Float, float: 1) == Float(1)

proc double[T](x: var T) =
  x *= 2
proc double(x: ValueNone) = discard
proc double(v: var Value) {.dispatchCase: v.}
var v = Integer(1)
double(v)
assert v == Integer(2)
v = Float(1.0)
double(v)
assert v == Float(2.0)

# see tests/docs for other macros

About

utility macros mostly for object variants

Topics

Resources

Stars

24 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

0