I have a function that takes some generic elements, which I wish to mutate, collect and return. As I understand it, calling into_iter
creates a consuming iterator, while map
takes those owned values. This is the case for Vec
below, however it is not the case for the &[T]
array. Why is this not the case? And while this is in no way an issue, is there such a way for the map
method to take owned elements of the &[T]
type?
fn iter_map<T>(array: &[T], vec: Vec<T>) {
// Why is this type `&T`?:
array.into_iter().map(|t: &T| ());
// In contrast to this vector, for example:
vec.into_iter().map(|t: T| ());
}