You can use
proc `==`(dst: var MyVM, src: MyVM) {.error: "One cannot simply copy a VM".}
Run
to ensure at compile-time that your VM are never copied, only moved.
For "do this on destruction":
type MyVM = object
# A wrapper to the C type "vm_t"
p: ptr vm_t
proc `=destroy`*(vm: var MyVM) =
if vm.p.isNil:
return
vm.p.releaseVM() # assuming the proc to release the VM is this
vm.p = nil
Run
For "do this on move"
proc `=sink`*(dst: var MyVM, src: MyVM) {.inline.} =
doThis()
# And now move the pointer
system.`=sink`(dst.p, src.p)
Run