]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #22313 - japaric:iter, r=aturon
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 16 Feb 2015 06:00:21 +0000 (11:30 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Tue, 17 Feb 2015 00:53:40 +0000 (06:23 +0530)
commitd264ef2b11683337c24cfb16e0335ab386df02ab
tree7470205f60983dd337b6ebcec633e8bd07725330
parente337a5728a3bedbae542c0c71e1c4185c75be21b
parente7273784c7a80d8099e495015753d70e63e6d432
Rollup merge of #22313 - japaric:iter, r=aturon

 `IntoIterator` now has an extra associated item:

``` rust
trait IntoIterator {
    type Item;
    type IntoIter: Iterator<Self=Self::Item>;
}
```

This lets you bind the iterator \"`Item`\" directly when writing generic functions:

``` rust
// hypothetical change, not included in this PR
impl Extend<T> for Vec<T> {
    // you can now write
    fn extend<I>(&mut self, it: I) where I: IntoIterator<Item=T> { .. }
    // instead of
    fn extend<I: IntoIterator>(&mut self, it: I) where I::IntoIter: Iterator<Item=T> { .. }
}
```

The downside is that now you have to write an extra associated type in your `IntoIterator` implementations:

``` diff
 impl<T> IntoIterator for Vec<T> {
+    type Item = T;
     type IntoIter = IntoIter<T>;

     fn into_iter(self) -> IntoIter<T> { .. }
 }
```

Because this breaks all downstream implementations of `IntoIterator`, this is a [breaking-change]

---

r? @aturon
src/libcollections/binary_heap.rs
src/libcollections/btree/map.rs
src/libcollections/btree/set.rs
src/libcollections/dlist.rs
src/libcollections/ring_buf.rs
src/libcollections/vec.rs
src/libcore/iter.rs
src/libcore/slice.rs
src/libstd/collections/hash/set.rs