Hi guys!
I just wanted to understand one aspect of the Rust's references Rules:
At any given moment, I can only have an unlimited number of immutable references of a variable OR a single mutable reference of a variable, correct?
In the program below, if I take the mut keyword from line 2, the program will of course complain. But, if the mut keyword on line 2 holds, why does Rust does not complain?
Thank you in advance!
fn main() {
let mut x = 10;
let _ref1 = &x;
let _ref2 = &x;
let _ref_mut = & mut x;
*_ref_mut = 9;
println!("{}", *_ref_mut);
}
Output:
9
Errors:
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 0.78s
Running `target/debug/playground`
