borrow dots for distinct types documented
This commit is contained in:
parent
cdb4d83ead
commit
7874c0efcb
3 changed files with 35 additions and 1 deletions
|
|
@ -1569,6 +1569,28 @@ currency. This can be solved with templates_.
|
||||||
defineCurrency(TEuro, int)
|
defineCurrency(TEuro, int)
|
||||||
|
|
||||||
|
|
||||||
|
The borrow pragma can also be used to annotate the distinct type to allow
|
||||||
|
certain builtin operations to be lifted:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
type
|
||||||
|
Foo = object
|
||||||
|
a, b: int
|
||||||
|
s: string
|
||||||
|
|
||||||
|
Bar {.borrow: `.`.} = distinct Foo
|
||||||
|
|
||||||
|
var bb: ref Bar
|
||||||
|
new bb
|
||||||
|
# field access now valid
|
||||||
|
bb.a = 90
|
||||||
|
bb.s = "abc"
|
||||||
|
|
||||||
|
Currently only the dot accessor can be borrowed in this way.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Void type
|
Void type
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
|
|
||||||
13
tests/distinct/tborrowdot.nim
Normal file
13
tests/distinct/tborrowdot.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo = object
|
||||||
|
a, b: int
|
||||||
|
s: string
|
||||||
|
|
||||||
|
Bar {.borrow: `.`.} = distinct Foo
|
||||||
|
|
||||||
|
var bb: ref Bar
|
||||||
|
new bb
|
||||||
|
bb.a = 90
|
||||||
|
bb.s = "abc"
|
||||||
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -4,7 +4,6 @@ version 0.9.4
|
||||||
- fix gensym capture bug
|
- fix gensym capture bug
|
||||||
- fix GC issues
|
- fix GC issues
|
||||||
|
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
====
|
====
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue