document usage of marshal.to; fixes #3150

This commit is contained in:
Araq
2018-09-03 09:44:44 +02:00
parent 7278f28740
commit ef771cde1a

View File

@@ -280,6 +280,17 @@ proc `$$`*[T](x: T): string =
proc to*[T](data: string): T =
## reads data and transforms it to a ``T``.
runnableExamples:
type
Foo = object
id: int
bar: string
let x = Foo(id: 1, bar: "baz")
# serialize
let y = ($$x)
# deserialize back to type 'Foo':
let z = y.to[:Foo]
var tab = initTable[BiggestInt, pointer]()
loadAny(newStringStream(data), toAny(result), tab)