2 ms·
In Rust's case, this becomes far less practical as soon as the closure's return type does not implement the Copy trait.
by eptcyka 8y ago
In Rust's case, this becomes far less practical as soon as the closure's return type does not implement the Copy trait.
- oconnor663 8y agoHere's an example that does something similar with Vec's: https://play.rust-lang.org/?gist=7a4ed9098a53831195c5189ba9cd904f&version=stable&mode=debug https://play.rust-lang.org/?gist=7a4ed9098a53831195c5189ba9c... I think the real nastiness happens if you want to have more than one closure over the same variables, when those variables aren't Copy. Because then when you try to `move` them in, the compiler yells at you. At that point you have to resort to putting them in an `Arc<Mutex>` or something like that. But that's par for the course with Rust: the compiler is preventing you from creating multiple mutable references to the same object.