use zoet::zoet; struct Array(Vec); #[zoet] impl Array { #[zoet(IntoIterator)] fn into_iterator(self) -> std::vec::IntoIter { self.0.into_iter() } // TODO: surprisingly tricky to implement // #[zoet(FromIterator)] // fn from_iter(ii: impl IntoIterator) -> Self { // Self(ii.into_iter().collect()) // } } // And the same, but with lifetimes. struct Slice<'a, T>(&'a mut [T]); #[zoet] impl<'a, T> Slice<'a, T> { #[zoet(IntoIterator)] fn iter(&'a self) -> std::slice::Iter<'a, T> { self.0.iter() } #[zoet(IntoIterator)] fn iter_mut(&'a mut self) -> std::slice::IterMut<'a, T> { self.0.iter_mut() } // TODO: surprisingly tricky to implement // #[zoet(FromIterator)] // fn from_iter(ii: impl IntoIterator) -> Self { // Self(ii.into_iter().collect()) // } } struct Array2(Vec); #[zoet] impl Array2 { #[zoet(IntoIterator)] fn into_iterator(self) -> IntoIter { IntoIter(self.0.into_iter()) } } struct IntoIter(std::vec::IntoIter); #[zoet] impl IntoIter { #[zoet(Iterator)] fn next(&mut self) -> Option { self.0.next() } #[zoet(DoubleEndedIterator)] fn next_back(&mut self) -> Option { self.0.next_back() } }