helper for working with distinct types

This commit is contained in:
Zahary Karadjov 2019-03-13 23:20:27 +02:00
parent 030c8e2cbe
commit c13420f1d0
1 changed files with 11 additions and 0 deletions

View File

@ -110,3 +110,14 @@ template saveFile*(Format: type, filename: string, args: varargs[untyped]) =
# TODO: This should use a proper output stream, instead of calling `encode` # TODO: This should use a proper output stream, instead of calling `encode`
writeFile(filename, Format.encode(args)) writeFile(filename, Format.encode(args))
template borrowSerialization*(Alias: distinct type,
OriginalType: distinct type) {.dirty.} =
proc writeValue*[Writer](writer: var Writer, value: Alias) =
mixin writeValue
writeValue(writer, OriginalType value)
proc readValue*[Reader](reader: var Reader, value: var Alias) =
mixin readValue
value = Alias reader.readValue(OriginalType)