Skip to content

Commit 9f90d66

Browse files
author
Jorge Aparicio
committed
impl IntoIterator for HashSet
1 parent afabb02 commit 9f90d66

File tree

1 file changed

+27
-1
lines changed
  • src/libstd/collections/hash

1 file changed

+27
-1
lines changed

src/libstd/collections/hash/set.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use default::Default;
1818
use fmt::Debug;
1919
use fmt;
2020
use hash::{self, Hash};
21-
use iter::{Iterator, ExactSizeIterator, IteratorExt, FromIterator, Map, Chain, Extend};
21+
use iter::{
22+
Iterator, IntoIterator, ExactSizeIterator, IteratorExt, FromIterator, Map, Chain, Extend,
23+
};
2224
use ops::{BitOr, BitAnd, BitXor, Sub};
2325
use option::Option::{Some, None, self};
2426

@@ -833,6 +835,30 @@ pub struct Union<'a, T: 'a, S: 'a> {
833835
iter: Chain<Iter<'a, T>, Difference<'a, T, S>>
834836
}
835837

838+
impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S>
839+
where T: Eq + Hash<H>,
840+
S: HashState<Hasher=H>,
841+
H: hash::Hasher<Output=u64>
842+
{
843+
type Iter = Iter<'a, T>;
844+
845+
fn into_iter(self) -> Iter<'a, T> {
846+
self.iter()
847+
}
848+
}
849+
850+
impl<T, S, H> IntoIterator for HashSet<T, S>
851+
where T: Eq + Hash<H>,
852+
S: HashState<Hasher=H>,
853+
H: hash::Hasher<Output=u64>
854+
{
855+
type Iter = IntoIter<T>;
856+
857+
fn into_iter(self) -> IntoIter<T> {
858+
self.into_iter()
859+
}
860+
}
861+
836862
#[stable(feature = "rust1", since = "1.0.0")]
837863
impl<'a, K> Iterator for Iter<'a, K> {
838864
type Item = &'a K;

0 commit comments

Comments
 (0)