diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2015-02-13 17:55:10 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2015-02-13 19:02:02 -0500 |
| commit | e7273784c7a80d8099e495015753d70e63e6d432 (patch) | |
| tree | 6e96958f2a8eaa48e8ac3e42781ab941e5c02dfc /src/libstd | |
| parent | cf636c233dfeef5abf0de8fb35e23c0a161810d2 (diff) | |
| download | rust-e7273784c7a80d8099e495015753d70e63e6d432.tar.gz rust-e7273784c7a80d8099e495015753d70e63e6d432.zip | |
add an associated `Item` type to `IntoIterator`
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 48 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 32 |
2 files changed, 80 insertions, 0 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 18dd122891d..241e409910f 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1372,6 +1372,8 @@ enum VacantEntryState<K, V, M> { NoElem(EmptyBucket<K, V, M>), } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V, S, H> IntoIterator for &'a HashMap<K, V, S> where K: Eq + Hash<H>, S: HashState<Hasher=H>, @@ -1384,6 +1386,22 @@ impl<'a, K, V, S, H> IntoIterator for &'a HashMap<K, V, S> } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V, S, H> IntoIterator for &'a HashMap<K, V, S> + where K: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type Item = (&'a K, &'a V); + type IntoIter = Iter<'a, K, V>; + + fn into_iter(self) -> Iter<'a, K, V> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap<K, V, S> where K: Eq + Hash<H>, S: HashState<Hasher=H>, @@ -1396,6 +1414,22 @@ impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap<K, V, S> } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap<K, V, S> + where K: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type Item = (&'a K, &'a mut V); + type IntoIter = IterMut<'a, K, V>; + + fn into_iter(mut self) -> IterMut<'a, K, V> { + self.iter_mut() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<K, V, S, H> IntoIterator for HashMap<K, V, S> where K: Eq + Hash<H>, S: HashState<Hasher=H>, @@ -1408,6 +1442,20 @@ impl<K, V, S, H> IntoIterator for HashMap<K, V, S> } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<K, V, S, H> IntoIterator for HashMap<K, V, S> + where K: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type Item = (K, V); + type IntoIter = IntoIter<K, V>; + + fn into_iter(self) -> IntoIter<K, V> { + self.into_iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> Iterator for Iter<'a, K, V> { type Item = (&'a K, &'a V); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index de3c0424c9a..7d735201bea 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -835,6 +835,8 @@ pub struct Union<'a, T: 'a, S: 'a> { iter: Chain<Iter<'a, T>, Difference<'a, T, S>> } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S> where T: Eq + Hash<H>, S: HashState<Hasher=H>, @@ -847,11 +849,41 @@ impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S> } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S> + where T: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<T, S, H> IntoIterator for HashSet<T, S> + where T: Eq + Hash<H>, + S: HashState<Hasher=H>, + H: hash::Hasher<Output=u64> +{ + type IntoIter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<T, S, H> IntoIterator for HashSet<T, S> where T: Eq + Hash<H>, S: HashState<Hasher=H>, H: hash::Hasher<Output=u64> { + type Item = T; type IntoIter = IntoIter<T>; fn into_iter(self) -> IntoIter<T> { |
