The problem is that Box<Iterator<A>> itself does not implement the Iterator trait. (I donβt know exactly why, maybe someone else can call back at this moment.)
You can fix it yourself:
impl<A> Iterator<A> for Box<Iterator<A>> { fn next(&mut self) -> Option<A> { self.next() } }
But since neither type nor trait is defined in your box, this is unacceptable. To get around this, you could define your own Iterator attribute, implement Iterator<A> for all Box<MyIter<A>> , and then implement MyIter<A> for all I types that satisfy Iterator<A> :
trait MyIter<A> : Iterator<A> {} impl<A, I: Iterator<A>> MyIter<A> for I {}
And you have to change your code to use as Box<MyIter<&uint>> :
fn main() { let xs = vec![0u, 1, 2, 3]; let mut boxed_iter = box xs.iter() as Box<MyIter<&uint>>; for x in boxed_iter { println!("{}", x); } }
(I added variability to boxed_iter , as this is required for iterators.)
source share