We can pass a Vec<f64>
to this function, but we cannot pass a VecDeque
, because that is two slices:
fn mean(v: &[f64]) -> f64 {
let sum = v.iter().sum();
sum / v.len() as f64
}
Is there a trait, something perhaps analogous to a C++ RandomAccessContainer
, that allows us to generically write code that operates on both Vec
and VecDeque
?
I believe you can use Iterator as a parameter.
There is a good article about iterator usage.