News for hackers. Stuff that matters.
Re:Rust for C++ programmers – part 2: control flow by pcwalton on Sunday April 20, 2014 @03:59AM (#7616193)
You'd have to overload "for" to detect whether the expression implemented Iterable or Iterator to decide what to do, and that was felt to be too complex (e.g. what if you implement both?) There was an attempt to have a unified Iterable trait at one point [1], but I believe it didn't work with the trait matching rules.

[1]: https://github.com/mozilla/rust/issues/7597

Re:Rust for C++ programmers – part 2: control flow by masklinn on Sunday April 20, 2014 @04:07AM (#7616212)
> You'd have to overload "for" to detect whether the expression implemented Iterable or Iterator to decide what to do

Iterator implements Iterable as a trivial self-return (by default), and `for` only and always takes an Iterable?

> what if you implement both?

Depends what sort of weirdness you're trying to do I guess.

> I believe it didn't work with the trait matching rules.

Ah. Too bad.

Re:Rust for C++ programmers – part 2: control flow by pcwalton on Sunday April 20, 2014 @04:11AM (#7616216)
Yeah, I would rather have "for" defined only to operate on Iterables. If we modified the trait matching rules we could probably do that backwards compatibly post 1.0.