3 ms·
Not to be the guy who brings Rust into the Go thread, but… Rust supports value semantics, and also supports `for player in &mut players { player.score = 0; }`.
by bobbylarrybobby 3y ago
Not to be the guy who brings Rust into the Go thread, but… Rust supports value semantics, and also supports `for player in &mut players { player.score = 0; }`.
- pjmlp 3y agoLikewise in other languages with similar value semantics, but as we know those are PhD features only relevant for folks playing with language research.
- tylerhou 3y agoIt’s a natural consequence of value semantics and not supporting references / pointers with range syntax :). (You can still write the same bug in Rust or C++ accidentally.)
- sapiogram 3y ago> You can still write the same bug in Rust I honestly don't think you can. If you try to iterate over values instead of references, you'll take ownership of the vector and not be able to use it again.
- tylerhou 3y agoIf the value is Copy, you will make a copy and won’t take ownership, right? (Iterate over a vector of ints). Granted Rust structs are not Copy by default. Same with any C++ class for which there is no copy constructor.