4 ms·
So, Rust has this very awesome thing where all variables are move by default, but types may opt in to be copied by implementing the Copy trait (a trait being th
by roblabla 4y ago
So, Rust has this very awesome thing where all variables are move by default, but types may opt in to be copied by implementing the Copy trait (a trait being the Rust equivalent of a Swift protocol).
This works exceedingly well. It essentially maps to what I want to do in almost all cases: Things that can trivially be copied (because they don't contain a resource) will usually work as you'd expect in any other programming language, while things that cannot (because they contain a resource like a file descriptor, or an owned pointer to some allocated memory) will indeed mark the old variable as unusable.
This is a really pleasant model to work with. So much so that I miss it terribly whenever I work in another language.
- thealistra 4y agoI believe this was in the swift roadmap to have an opt-in borrow semantics for a block of code, if you want to do low level systems programming - just like rust. But I guess it didn't fit to migrate from current obj-c ecosystem so they left it for later.