diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2020-07-20 07:50:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-20 07:50:19 +0200 |
commit | 71dd5f85b9a13d97ea0c74338722bf08a9ae6286 (patch) | |
tree | 0c8757d1a835b334bcac8dc252622bd7b9073549 /lib/std/isolation.nim | |
parent | bb1adf6a706190883fa57a0208ba8e3118235256 (diff) | |
download | Nim-71dd5f85b9a13d97ea0c74338722bf08a9ae6286.tar.gz |
'isolate' builtin; refs https://github.com/nim-lang/RFCs/issues/244 (#15011)
Diffstat (limited to 'lib/std/isolation.nim')
-rw-r--r-- | lib/std/isolation.nim | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/std/isolation.nim b/lib/std/isolation.nim new file mode 100644 index 000000000..7ca5f0080 --- /dev/null +++ b/lib/std/isolation.nim @@ -0,0 +1,31 @@ +# +# +# Nim's Runtime Library +# (c) Copyright 2020 Nim contributors +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## This module implements the `Isolated[T]` type for +## safe construction of isolated subgraphs that can be +## passed efficiently to different channels and threads. + +type + Isolated*[T] = object ## Isolated data can only be moved, not copied. + value: T + +proc `=`*[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 + `=sink`(dest.value, src.value) + +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`. + ## Please read https://github.com/nim-lang/RFCs/issues/244 + ## for more details. |