diff options
Diffstat (limited to 'lib/std/isolation.nim')
-rw-r--r-- | lib/std/isolation.nim | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/std/isolation.nim b/lib/std/isolation.nim index 7ca5f0080..b03e00651 100644 --- a/lib/std/isolation.nim +++ b/lib/std/isolation.nim @@ -10,12 +10,15 @@ ## This module implements the `Isolated[T]` type for ## safe construction of isolated subgraphs that can be ## passed efficiently to different channels and threads. +## +## .. warning:: This module is experimental and its interface may change. +## type - Isolated*[T] = object ## Isolated data can only be moved, not copied. + Isolated*[T] {.sendable.} = object ## Isolated data can only be moved, not copied. value: T -proc `=`*[T](dest: var Isolated[T]; src: Isolated[T]) {.error.} +proc `=copy`*[T](dest: var Isolated[T]; src: Isolated[T]) {.error.} proc `=sink`*[T](dest: var Isolated[T]; src: Isolated[T]) {.inline.} = # delegate to value's sink operation @@ -25,7 +28,22 @@ proc `=destroy`*[T](dest: var Isolated[T]) {.inline.} = # delegate to value's destroy operation `=destroy`(dest.value) -func isolate*[T](value: sink T): Isolated[T] {.magic: "Isolate".} - ## Create an isolated subgraph from the expression `value`. +func isolate*[T](value: sink T): Isolated[T] {.magic: "Isolate".} = + ## Creates an isolated subgraph from the expression `value`. + ## Isolation is checked at compile time. + ## ## Please read https://github.com/nim-lang/RFCs/issues/244 ## for more details. + Isolated[T](value: value) + +func unsafeIsolate*[T](value: sink T): Isolated[T] = + ## Creates an isolated subgraph from the expression `value`. + ## + ## .. warning:: The proc doesn't check whether `value` is isolated. + ## + Isolated[T](value: value) + +func extract*[T](src: var Isolated[T]): T = + ## Returns the internal value of `src`. + ## The value is moved from `src`. + result = move(src.value) |