I have a function that is supposed to accept any container supporting IntoIterator
. I also want that each element in that container must implement a certain trait ABC
which I have defined. How would I go about this?
fn foo<I, T>(iter: I) where T: ABC, I: IntoIterator<Item=T> { ... }
should do the trick.
1 Like
Oh, nice! thank you.
This is a bit simpler:
fn foo<I>(iter: I) where I: IntoIterator, I::Item: ABC { ... }
4 Likes
Another way to write it is:
fn foo<I: IntoIterator<Item = impl ABC>>(iter: I) {}
2 Likes