From ef771cde1ae9cf2da9b39c7444a6cae98575d255 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 09:44:44 +0200 Subject: [PATCH] document usage of marshal.to; fixes #3150 --- lib/pure/marshal.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pure/marshal.nim b/lib/pure/marshal.nim index 980439759..b0bcfe535 100644 --- a/lib/pure/marshal.nim +++ b/lib/pure/marshal.nim @@ -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)