4 ms·
You actually can't define two `&mut` references to the same data in Rust. It's invalid Rust code; if the compiler notices, it'll refuse to compile, and if it do
by wizzwizz4 5y ago
You actually can't define two `&mut` references to the same data in Rust. It's invalid Rust code; if the compiler notices, it'll refuse to compile, and if it doesn't notice, your code will randomly break.
- Yoric 5y agoYou can define two `*mut`, though, in unsafe code.
- anderskaseorg 5y agoA better option is to use Cell or RefCell; they allow completely safe shared mutability in single-threaded code. https://doc.rust-lang.org/std/cell/ https://doc.rust-lang.org/std/cell/
- Yoric 5y agoI'm aware of that :) I'm just trying to decypher that cryptic sentence from the OP.
- pwdisswordfish9 5y agoYou can, just not at the same time.