summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Adam Hankiewicz <gradha@imap.cc>2014-08-05 11:25:54 +0200
committerGrzegorz Adam Hankiewicz <gradha@imap.cc>2014-08-05 11:25:54 +0200
commit00f56b20d7e2edb903c7c486574ad793a078667a (patch)
tree5b08696c6a0d00deca8fca56448d917324d25ec7 /lib
parent915d3291ab57d59e41877c98dba97d6388c56a35 (diff)
downloadNim-00f56b20d7e2edb903c7c486574ad793a078667a.tar.gz
Adds usage example to typetraits.name().
Credit goes to fowl (http://forum.nimrod-lang.org/t/430).
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/typetraits.nim23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim
index e7bd363cf..3203ee699 100644
--- a/lib/pure/typetraits.nim
+++ b/lib/pure/typetraits.nim
@@ -11,7 +11,26 @@
 ## working with types
 
 proc name*(t: typedesc): string {.magic: "TypeTrait".}
-  ## Returns the name of the given type
+  ## Returns the name of the given type.
+  ##
+  ## Example:
+  ##
+  ## .. code-block::
+  ##
+  ##   import typetraits
+  ##
+  ##   proc `$`*[T](some:typedesc[T]): string = name(T)
+  ##
+  ##   template test(x): stmt =
+  ##     echo "type: ", type(x), ", value: ", x
+  ##
+  ##   test 42
+  ##   # --> type: int, value: 42
+  ##   test "Foo"
+  ##   # --> type: string, value: Foo
+  ##   test(@['A','B'])
+  ##   # --> type: seq[char], value: @[A, B]
+
 
 proc arity*(t: typedesc): int {.magic: "TypeTrait".}
-  ## Returns the arity of the given type
\ No newline at end of file
+  ## Returns the arity of the given type