I don’t see anything wrong so far, but I also don’t quite understand your question— Can you give a little bit more information about what output you’re looking for, or the things you’ve tried that didn’t work?
By convention, .iter() corresponds to impl<'a> IntoIterator for &'a Struct and .iter_mut() corresponds to impl<'a> IntoIterator for &'a mut Struct.
impl<'a> IntoIterator for &'a NeuralLayer {
type IntoIter = std::slice::Iter<'a, Neuron>;
type Item = &'a Neuron;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl<'a> IntoIterator for &'a mut NeuralLayer {
type IntoIter = std::slice::IterMut<'a, Neuron>;
type Item = &'a mut Neuron;
fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}
If you also want an owning iterator, that would just be impl Iterator for NeuralLayer (and by convention, consumers would call the trait method .into_iter() directly).
I think @quinedot answered your question, but just in case: Are you asking how you can return an impl Iterator<...> so that you're not referencing the slice iterator types? Like this: