#Confused about iterator / generics

6 messages · Page 1 of 1 (latest)

lunar brook
#

I'm trying to follow https://rust-lang.github.io/api-guidelines/flexibility.html#functions-minimize-assumptions-about-parameters-by-using-generics-c-generic.

Right now I have a function that takes in a &Vec<T>. If I change it to take in a IntoIterator, how do I call this function with the old arguments? Minimal example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3ae057aee988bac8835de4d45e54a135

Thanks.

severe socket
#

Its not an iterator over i64

#

?play ```rs
fn foo1<'a, I: IntoIterator<Item = &'a i64>>(iter: I) { /* ... */ }

fn foo2(c: &Vec<i64>) {
foo1(c);
}

fierce sandalBOT
severe socket
#

?play ```rs
fn foo1<I: IntoIterator<Item = i64>>(iter: I) { /* ... */ }

fn foo2(c: &Vec<i64>) {
foo1(c.iter().copied());
}

fierce sandalBOT