Skip to content

Commit 96bdbbc

Browse files
committed
add pointers.cast: allow running cast in UFCS/method call syntax chains
1 parent ea18f85 commit 96bdbbc

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
- Added `jssets` module, Set for the JavaScript target
2020
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2121
- Added `jsheaders` module for [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) for the JavaScript target.
22+
- Added module `pointers` containing `toUncheckedArray`, UFCS/MCS `cast`

src/fusion/pointers.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ proc toUncheckedArray*[T](a: ptr T): ptr UncheckedArray[T] {.inline.} =
1515
pa[0] += 5
1616
doAssert a[1] == 105
1717
cast[ptr UncheckedArray[T]](a)
18+
19+
proc `cast`*[T](a:T, T2: typedesc): T2 =
20+
## allows running `cast` in UFCS/method call syntax chains.
21+
## Unsafe as it calls `cast`.
22+
runnableExamples:
23+
proc square(a: auto): auto = a*a
24+
doAssert 3.square.cast(float).square == cast[float](3.square).square
25+
cast[T2](a)

0 commit comments

Comments
 (0)