diff --git a/NEP-2-Catching-up-with-C---and-Rust:-Ownership,-destructors,-unique-pointers.md b/NEP-2-Catching-up-with-C---and-Rust:-Ownership,-destructors,-unique-pointers.md index 22f6fa6..dc7ddbc 100644 --- a/NEP-2-Catching-up-with-C---and-Rust:-Ownership,-destructors,-unique-pointers.md +++ b/NEP-2-Catching-up-with-C---and-Rust:-Ownership,-destructors,-unique-pointers.md @@ -50,5 +50,12 @@ proc `=`(dst: var MyType; src: MyType) = dst.resources = src ``` +I just heard, that self assignment on types that have deinitialization would not work anymore. This can be handled by implementing some logic that checks weather it is selft assignment, or by simply declaring self assignment illegal. One version that works with self assignment is the following (again in psoudocode), but it still needs to explain what move semantics are. +```Nim +proc `=`(dst: var MyType; src: MyType) = + tmp <- copy(src) + destroy(dst) + dst <- tmp +```