I'm trying to create a function that takes a &[Vec<u64>]
and returns vector of tuple "coordinates" for the largest i64
in each row using iterators. I have it working on concrete types, but I want it to be generic over T
and bounded to iterable types. My code so far:
fn find_largest_per_row<T>(input: &[T]) -> Vec<(usize, usize)>
where
T: IntoIterator<Item = u64>,
{
input
.iter()
.enumerate()
.map(|(r, v)| {
v.into_iter()
.enumerate()
.max_by_key(|&(_, v)| v)
.map(|(c, _)| (r, c))
.unwrap()
})
.collect::<Vec<_>>()
}
I'm getting:
cannot move out of `*v` which is behind a shared reference
How do I resolve this? I realize T
is a reference so I tried .cloned()
, but that didn't work.
Also, for IntoIterator<Item=u64>
, do I need to specify u64
or can I provide something more generic?