I have a function fthat needs to be called like this:
struct S;
let s = &S;
f(&[(s, &[0.1, 0.2, 0.3]), (s, &[0.5, 0.6])]);
for a convenient interface, I want to fprocess any type IntoIterator. At the moment, my signature
fn f<'a, I, J: 'a>(iter: I)
where
I: IntoIterator<Item = &'a (&'a S, J)>,
J: IntoIterator<Item = &'a f32>
Unfortunately, the compiler treats slices as arrays of fixed size, so I got this error:
error[E0308]: mismatched types
|
142 | f(&[(s, &[0.1, 0.2, 0.3]), (s, &[0.5, 0.6])]);
| ^^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements
|
= note: expected type `&[{float}; 3]`
found type `&[{float}; 2]`
replacing Jwith Vec<f32>works, but that’s not how I want it.
First question: is there a way to handle this, that I can name the function as I mentioned? At first I thought that this can be solved with the help of a Grade of a higher rank , but they are available only for the parameters of life.
: , , IntoIterator? J::into_iter()?