From 07e3f86f9969337551ec42d4cababb973b22e6d0 Mon Sep 17 00:00:00 2001 From: flaviut Date: Fri, 20 Jun 2014 09:36:05 -0400 Subject: [PATCH] Add {.borrow: `.`.} --- content/types/distinct.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/content/types/distinct.md b/content/types/distinct.md index 5881ebc..8227ef1 100644 --- a/content/types/distinct.md +++ b/content/types/distinct.md @@ -21,4 +21,15 @@ proc `*` *(a, b: Dollars): Dollars {.borrow.} proc `+` *(a, b: Dollars): Dollars {.borrow.} a = 20.Dollars * 20.Dollars ``` - \ No newline at end of file + +When creating a distinct type from an object type, none of its fields are carried over. If the fields are wanted, they can be brought over through an overloading of the `{.borrow.}` pragma. If they are not borrowed, they cannot be accessed. + +``` nimrod +type + Foo = object + a: int + MyFoo {.borrow: `.`.} = distinct Foo + +var value: MyFoo +echo value.a # Works +``` \ No newline at end of file