document usage of marshal.to; fixes #3150
This commit is contained in:
parent
7278f28740
commit
ef771cde1a
1 changed files with 11 additions and 0 deletions
|
|
@ -280,6 +280,17 @@ proc `$$`*[T](x: T): string =
|
||||||
|
|
||||||
proc to*[T](data: string): T =
|
proc to*[T](data: string): T =
|
||||||
## reads data and transforms it to a ``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]()
|
var tab = initTable[BiggestInt, pointer]()
|
||||||
loadAny(newStringStream(data), toAny(result), tab)
|
loadAny(newStringStream(data), toAny(result), tab)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue