diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-16 11:30:21 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-17 06:23:40 +0530 |
| commit | d264ef2b11683337c24cfb16e0335ab386df02ab (patch) | |
| tree | 7470205f60983dd337b6ebcec633e8bd07725330 /src/libcollections/enum_set.rs | |
| parent | e337a5728a3bedbae542c0c71e1c4185c75be21b (diff) | |
| parent | e7273784c7a80d8099e495015753d70e63e6d432 (diff) | |
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
Diffstat (limited to 'src/libcollections/enum_set.rs')
| -rw-r--r-- | src/libcollections/enum_set.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index da533d34703..5c37be188fe 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -257,6 +257,8 @@ impl<E:CLike> FromIterator<E> for EnumSet<E> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike { type IntoIter = Iter<E>; @@ -265,6 +267,16 @@ impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike { + type Item = E; + type IntoIter = Iter<E>; + + fn into_iter(self) -> Iter<E> { + self.iter() + } +} + impl<E:CLike> Extend<E> for EnumSet<E> { fn extend<I: Iterator<Item=E>>(&mut self, iterator: I) { for element in iterator { |
