Ultimately, we want to provide “associated types” as part of a trait. Something like:
trait Set<A> {
type Items<'a>: Iterator<&'a A>;
type MoveItems: Iterator<A>;
fn iter(&self) -> Items;
fn move_iter(self) -> MoveItems;
...
}
Then each set implementation could provide its own iterator types, and it would all be unboxed.
Unfortunately, trait objects are a problematic workaround not just because of allocation concerns, but also because you can’t call generic methods on them, which rule out a lot of useful Iterator functionality.
So, sadly, I think iterators on these traits will probably need to await a language feature like associated types (there are a couple of other possibilities.) I’m not sure when the feature is likely to happen, but we’re actively thinking about it.