Scala has a similar design, with the following traits: - TraversableOnce: can be internally iterated once (has a foreach() method that takes a closure) - Traversable: can be internally iterated unlimited times (has a foreach() method that takes a closure) - Iterable: can be externally iterated (has an iterator() method that returns an Iterator trait)
The way it works is that Iterable extends Traversable, which extends TraversableOnce, and the for loop just uses TraversableOnce, and Iterable has a default implementation of the TraversableOnce foreach() function using the iterator() function. Also, the Iterator trait itself extends TraversableOnce, implementing foreach() by mutating itself. It might be a good idea to investigate copying this design.
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev