i have a function that takes a shared reference to a list of lists (this may either be on the heap or be static data)
depending on its other arguments, the function may index the outer list and clone one of the inner lists into a Vec.
i'm struggling to figure out the correct generic bounds. the problem is that &&[T]
doesn't implement IntoIterator
, but i need to use the &Vec<T>
implementation of IntoIterator.
Like so?
fn example<T, I: AsRef<[T]>>(lol: &[I]) {
for list in lol {
for item in list.as_ref() {
}
}
}
2 Likes
I guess I wanted it to work for any iterator, but I don't see myself using linked lists in for this anytime soon, so this is probably good enough.
You can do that too.
pub fn example<'a, T, I>(lol: &'a [I])
where
&'a I: IntoIterator<Item = T>,
{
for list in lol {
for item in list {
todo!()
}
}
}
Note that T
here includes a reference when I
is &[_]
or &Vec<_>
.
1 Like
this is basically what i tried, but i was using map and collect, and it seems that messed things up...
the code is long replaced, i'd have to dig through the git history to find it, and the for
solution is cleaner anyways.