Skip to content

Commit

Permalink
impl IntoIterator for HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Feb 2, 2015
1 parent afabb02 commit 9f90d66
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/libstd/collections/hash/set.rs
Expand Up @@ -18,7 +18,9 @@ use default::Default;
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};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9f90d66

Please sign in to comment.