4 ms·
No. You can't move an element out of an array in Rust. What Ollie said is true for local variables, and collections generally support some kind of "move elemen
by roca 7y ago
No. You can't move an element out of an array in Rust.
What Ollie said is true for local variables, and collections generally support some kind of "move element(s) out of the collection" API (e.g. Vec::pop(), T::into_iter()).
- gumby 7y agoSo rust can do it in a subset of cases, such that it can make a stronger assertion; C++ can do it in the general case, and is therefore unable to make the stronger assertion. Neither is correct vs the other, rather they reflect different choice points in the language possibility space.
- roca 7y agoYou can do a C++ style "swap object with a placeholder" move in Rust, easily, with std::mem::replace(). There's no advantage for C++ here.