cc_traits/impls/std/
hashset.rs1use crate::{
2 Clear, Collection, CollectionMut, CollectionRef, Get, Insert, Iter, Len, Remove,
3 SimpleCollectionMut, SimpleCollectionRef,
4};
5use std::{borrow::Borrow, collections::HashSet, hash::Hash};
6
7impl<T> Collection for HashSet<T> {
8 type Item = T;
9}
10
11impl<T> CollectionRef for HashSet<T> {
12 type ItemRef<'a> = &'a T where Self: 'a;
13
14 crate::covariant_item_ref!();
15}
16
17impl<T> CollectionMut for HashSet<T> {
18 type ItemMut<'a> = &'a mut T where Self: 'a;
19
20 crate::covariant_item_mut!();
21}
22
23impl<T> SimpleCollectionRef for HashSet<T> {
24 crate::simple_collection_ref!();
25}
26
27impl<T> SimpleCollectionMut for HashSet<T> {
28 crate::simple_collection_mut!();
29}
30
31impl<T> Len for HashSet<T> {
32 #[inline(always)]
33 fn len(&self) -> usize {
34 self.len()
35 }
36
37 #[inline(always)]
38 fn is_empty(&self) -> bool {
39 self.is_empty()
40 }
41}
42
43impl<'a, Q, T: Hash + Eq> Get<&'a Q> for HashSet<T>
44where
45 T: Borrow<Q>,
46 Q: Hash + Eq + ?Sized,
47{
48 fn get(&self, value: &'a Q) -> Option<&T> {
49 self.get(value)
50 }
51}
52
53impl<T: Hash + Eq> Insert for HashSet<T> {
54 type Output = bool;
55
56 #[inline(always)]
57 fn insert(&mut self, t: T) -> bool {
58 self.insert(t)
59 }
60}
61
62impl<'a, Q, T: Hash + Eq> Remove<&'a Q> for HashSet<T>
63where
64 T: Borrow<Q>,
65 Q: Hash + Eq + ?Sized,
66{
67 #[inline(always)]
68 fn remove(&mut self, t: &'a Q) -> Option<T> {
69 self.take(t)
70 }
71}
72
73impl<T: Hash + Eq> Clear for HashSet<T> {
74 #[inline(always)]
75 fn clear(&mut self) {
76 self.clear()
77 }
78}
79
80impl<T> Iter for HashSet<T> {
81 type Iter<'a> = std::collections::hash_set::Iter<'a, T> where Self: 'a;
82
83 #[inline(always)]
84 fn iter(&self) -> Self::Iter<'_> {
85 self.iter()
86 }
87}