3 ms·
when I started moving from C++ to Rust I found the easiest initial way to make sense of the borrow checker was to basically imagine that almost every argument p
by cmrdporcupine 4y ago
when I started moving from C++ to Rust I found the easiest initial way to make sense of the borrow checker was to basically imagine that almost every argument passed in a function call was wrapped in a std::move.
- School-Cotton 4y agoevery argument is passed by move, not just almost every. Types that implement Copy are still moved. Copy just means “the original value is still usable after move”.
- cmrdporcupine 4y agofair enough, but also the semantics of a Rust 'move' aren't identical to C++ std::move anyways. you can "get it back" after the function call, as it's a borrow, not a move. Makes me wonder out loud if the C++ community isn't going to add some kind of std::borrow/std::return_borrowed to the language. If that's even feasible with the type system and reference system as it is today.