I would like to do the following and allow my perform function to take an iterator with &usize or with usize items as below.
fn perform<'a, I>(values: I) -> usize
where
I: Iterator<Item = &'a usize>,
{
*values.max().unwrap()
}
fn main() {
let v: Vec<usize> = vec![1, 2, 3, 4];
// Works.
let result = perform(v.iter());
print!("Result: {}", result);
// Does not work: `expected `&usize`, found `usize``.
let result = perform(v.iter().map(|v| v * 2));
print!("Result again: {}", result)
}
Playground example here.