I have an implementation of a FromIterator of references:
impl<'a> FromIterator<&'a T> for Type<T> {
fn from_iter<I: IntoIterator<Item = &'a T>>(iter: I) -> Self {
...
}
}
I am trying to implement the non-reference version, without copy-pasting the implementation
impl FromIterator<T> for Type<T> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
Self::from_iter(iter.into_iter().????)
}
}
however, I can't find the API to convert an Iter of values into an Iter of references (can I?). Does anyone knows what should I place on the ?????
The overall idea is to DRY the code of both implementations. In both cases, the implementation only uses references.
I could place the implementation on the iterator of values, and call Self::from_iter(iter.into_iter().cloned()), but that would cause an extra clone per item when the user has an iterator of references.