]> git.lizzy.rs Git - rust.git/commitdiff
impl IntoIterator for HashSet
authorJorge Aparicio <japaricious@gmail.com>
Sat, 31 Jan 2015 17:05:58 +0000 (12:05 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Mon, 2 Feb 2015 18:38:32 +0000 (13:38 -0500)
src/libstd/collections/hash/set.rs

index c6dcb0d230ff7cd54783ef4ce482f5a65bbf80ec..755235cbace09c3bdbd32950088c1d5ec30f024e 100644 (file)
@@ -18,7 +18,9 @@
 use fmt::Debug;
 use fmt;
 use hash::{self, Hash};
-use iter::{Iterator, ExactSizeIterator, IteratorExt, FromIterator, Map, Chain, Extend};
+use iter::{
+    Iterator, IntoIterator, ExactSizeIterator, IteratorExt, FromIterator, Map, Chain, Extend,
+};
 use ops::{BitOr, BitAnd, BitXor, Sub};
 use option::Option::{Some, None, self};
 
@@ -833,6 +835,30 @@ pub struct Union<'a, T: 'a, S: 'a> {
     iter: Chain<Iter<'a, T>, Difference<'a, T, S>>
 }
 
+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 Iter = Iter<'a, T>;
+
+    fn into_iter(self) -> Iter<'a, T> {
+        self.iter()
+    }
+}
+
+impl<T, S, H> IntoIterator for HashSet<T, S>
+    where T: Eq + Hash<H>,
+          S: HashState<Hasher=H>,
+          H: hash::Hasher<Output=u64>
+{
+    type Iter = IntoIter<T>;
+
+    fn into_iter(self) -> IntoIter<T> {
+        self.into_iter()
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, K> Iterator for Iter<'a, K> {
     type Item = &'a K;