summary refs log tree commit diff stats
path: root/doc/destructors.rst
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2020-01-17 11:44:06 +0000
committerGitHub <noreply@github.com>2020-01-17 11:44:06 +0000
commitf51613e262a18f6f56119d73f4c1431c8ebf6d3a (patch)
tree9b5894d7fdbb48972d5f4355deddd5dd972657d1 /doc/destructors.rst
parent76269074014b672582bc630ff393a95e5e21dcec (diff)
downloadNim-f51613e262a18f6f56119d73f4c1431c8ebf6d3a.tar.gz
make sink operator optional (#13068)
* make sink operator optional

* bug fix, add changelog entry

* Trigger build

* fix one regression

* fix test

* Trigger build

* fix typos
Diffstat (limited to 'doc/destructors.rst')
-rw-r--r--doc/destructors.rst8
1 files changed, 6 insertions, 2 deletions
diff --git a/doc/destructors.rst b/doc/destructors.rst
index 1ca51ddf1..d2027102a 100644
--- a/doc/destructors.rst
+++ b/doc/destructors.rst
@@ -53,7 +53,8 @@ written as:
         a.data[i] = b.data[i]
 
   proc `=sink`*[T](a: var myseq[T]; b: myseq[T]) =
-    # move assignment
+    # move assignment, optional.
+    # Compiler is using `=destroy` and `copyMem` when not provided
     `=destroy`(a)
     a.len = b.len
     a.cap = b.cap
@@ -130,7 +131,10 @@ A `=sink` hook moves an object around, the resources are stolen from the source
 and passed to the destination. It is ensured that source's destructor does
 not free the resources afterwards by setting the object to its default value
 (the value the object's state started in). Setting an object ``x`` back to its
-default value is written as ``wasMoved(x)``.
+default value is written as ``wasMoved(x)``. When not provided the compiler
+is using a combination of `=destroy` and `copyMem` instead. This is efficient
+hence users rarely need to implement their own `=sink` operator, it is enough to
+provide `=destroy` and `=`, compiler will take care about the rest.
 
 The prototype of this hook for a type ``T`` needs to be: