//@ run-pass #![feature(fn_delegation)] #![allow(incomplete_features)] use std::iter::{Iterator, Map}; pub mod same_trait { use super::*; pub struct MapOuter { pub inner: Map } impl Iterator for MapOuter where F: FnMut(I::Item) -> B, { type Item = as Iterator>::Item; reuse Iterator::{next, fold} { self.inner } } } use same_trait::MapOuter; mod another_trait { use super::*; trait ZipImpl { type Item; fn next(&mut self) -> Option; } pub struct Zip { pub a: A, pub b: B, } impl ZipImpl for Zip { type Item = (A::Item, B::Item); fn next(&mut self) -> Option<(A::Item, B::Item)> { let x = self.a.next()?; let y = self.b.next()?; Some((x, y)) } } impl Iterator for Zip { type Item = (A::Item, B::Item); // Parameters are inherited from `Iterator::next`, not from `ZipImpl::next`. // Otherwise, there would be a compilation error due to an unconstrained parameter. reuse ZipImpl::next; } } use another_trait::Zip; fn main() { { let x = vec![1, 2, 3]; let iter = x.iter().map(|val| val * 2); let outer_iter = MapOuter { inner: iter }; let val = outer_iter.fold(0, |acc, x| acc + x); assert_eq!(val, 12); } { let x = vec![1, 2]; let y = vec![4, 5]; let mut zip = Zip { a: x.iter(), b: y.iter() }; assert_eq!(zip.next(), Some((&1, &4))); assert_eq!(zip.next(), Some((&2, &5))); } }