Skip to content

Commit

Permalink
Auto merge of #235 - smmalis37:patch-1, r=Amanieu
Browse files Browse the repository at this point in the history
Implement `From<HashMap<T, ()>>` for `HashSet<T>`.

Closes #219.
  • Loading branch information
bors committed Feb 5, 2021
2 parents 91afba3 + ae8c196 commit b5b5be8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,15 @@ where
}
}

impl<T, S, A> From<HashMap<T, (), S, A>> for HashSet<T, S, A>
where
A: Allocator + Clone,
{
fn from(map: HashMap<T, (), S, A>) -> Self {
Self { map }
}
}

impl<T, S, A> FromIterator<T> for HashSet<T, S, A>
where
T: Eq + Hash,
Expand Down Expand Up @@ -2038,6 +2047,23 @@ mod test_set {
assert_eq!(i, expected.len());
}

#[test]
fn test_from_map() {
let mut a = crate::HashMap::new();
a.insert(1, ());
a.insert(2, ());
a.insert(3, ());
a.insert(4, ());

let a: HashSet<_> = a.into();

assert_eq!(a.len(), 4);
assert!(a.contains(&1));
assert!(a.contains(&2));
assert!(a.contains(&3));
assert!(a.contains(&4));
}

#[test]
fn test_from_iter() {
let xs = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9];
Expand Down

0 comments on commit b5b5be8

Please sign in to comment.