I’ve been working through the recommended exercises in the beta version of the Rust book. After completing one of them last night, I awoke this morning to the realization that i’m not sure how my program passed the borrow checker. Here is the relevant snippet of code:
[CODE]
fn main() {
let mut v = vec![0];
let (num, freq) = mode(&v);
println!("The average is {:?}.", average(&v));
println!("The median is {:?}.", median(&mut v));
if freq > 1 {
println!("The mode is {:?}, which occurs {:?} times.", num, freq);
} else {
println!(“There is no mode”);
}
}
[/CODE]
According to my understanding of the reference rules i’m only allowed to have just one mutable reference or any number of immutable references, but not both. I don’t understand how the above code isn’t an example of having both and thus shouldn’t run.