summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-09-03 09:44:44 +0200
committerAraq <rumpf_a@web.de>2018-09-03 09:44:44 +0200
commitef771cde1ae9cf2da9b39c7444a6cae98575d255 (patch)
tree7c90755d763ede57fd7746f5ff74e54dc935678a /lib
parent7278f28740a1bce4bb8896b4f7553694e7970f8f (diff)
downloadNim-ef771cde1ae9cf2da9b39c7444a6cae98575d255.tar.gz
document usage of marshal.to; fixes #3150
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/marshal.nim11
1 files changed, 11 insertions, 0 deletions
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)