Medium
Creating two mutable references to the same value
What happens when this code is compiled?
main.rs
struct Counter {
value: i32,
}
impl Counter {
fn increment(&mut self) {
self.value += 1;
}
}
fn main() {
let mut c = Counter { value: 0 };
let r1 = &mut c;
let r2 = &mut c;
r1.increment();
r2.increment();
println!("{}", c.value);
}7 of 53 in Rust