Skip to content

Commit 33c2a8d

Browse files
committed
add pointers.cast: allow running cast in UFCS/method call syntax chains
1 parent a24a381 commit 33c2a8d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## additions and changes
22

3-
- Added module `pointers` containing `toUncheckedArray`
3+
- 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)