I'm a very beginner to Rust and I got confused by Rust functional programming style code. Assume
freq is a vector containing non negative integers. The below code makes me confused.
Get the largest index with a positive value.
let key_max = (0..denom).rev().step_by(1).filter(|&i| freq[i] > 0).next().unwrap();
Get the number of positive values in
let size = freq.iter().filter(|&&f| f > 0u32).count();
- why the first line of code use
&) while the second line of code uses
- In general, why do we need
&&fin the second line of code? Why doesn't Rust make it simple to require only a single