[rust-dev] iter library

Marijn Haverbeke marijnh at gmail.com
Fri Apr 27 23:03:40 PDT 2012


> Sorry if I didn't make my purpose clear.  The wrapper type is to distinguish
> the different modes of iteration.

What Joe meant is that you could simply write multiple impls on the
same type with different names for the various modes of iteration.

    impl of iter for maptype { ... }
    impl iter_keys of iter for maptype { ... }
    impl iter_vals of iter for maptype { ... }

You could then do 'import map::iter_keys;` at the top of a block to
force the key-iterating impl to take precedence there.

I think the ergonomics of this kind of trick didn't work out as well
as hoped, though. You'd get multiple applicable impl errors when
importing `map::*`, and seeing which impl is currently closest in a
scope is somewhat indirect and confusing.

Best,
Marijn


More information about the Rust-dev mailing list