mirror of
https://github.com/status-im/nim-rlp.git
synced 2025-02-20 17:58:08 +00:00
18 lines
443 B
Nim
18 lines
443 B
Nim
|
import macros
|
||
|
|
||
|
template enumerateRlpFields*[T](x: T, op: untyped) =
|
||
|
for f in fields(x): op(f)
|
||
|
|
||
|
macro rlpFields*(T: typedesc, fields: varargs[untyped]): untyped =
|
||
|
var body = newStmtList()
|
||
|
let
|
||
|
ins = genSym(nskParam, "instance")
|
||
|
op = genSym(nskParam, "op")
|
||
|
|
||
|
for field in fields:
|
||
|
body.add quote do: `op`(`ins`.`field`)
|
||
|
|
||
|
result = quote do:
|
||
|
template enumerateRlpFields*(`ins`: `T`, `op`: untyped) {.inject.} =
|
||
|
`body`
|