I have written a function to map over vectors. The method definition expects 3 generic parameters and defines over a input vector and function:
pub fn map<F, A, B>(mapFn: F, vect: &[A]) -> &[B]
where
F: Fn(A) -> B,
{
let mut list = vec![];
for v in vect {
let mut value = mapFn(v);
list.push(value);
}
&list[..]
}
I get this error:
error[E0308]: mismatched types
--> src/main.rs:8:31
|
8 | let mut value = mapFn(v); // <------ This is where I get the error
| ^ expected type parameter, found &A
|
= note: expected type `A`
found type `&A`
I also checked Generics Error: expected type parameter, found struct, but it did not seem to be about the same problem.