nautilus_core/
collections.rs1use std::{
19 collections::{HashMap, HashSet},
20 fmt::{Debug, Display},
21 hash::Hash,
22};
23
24pub trait SetLike {
26 type Item: Hash + Eq + Display + Clone;
27
28 fn contains(&self, item: &Self::Item) -> bool;
29 fn is_empty(&self) -> bool;
30}
31
32impl<T, S> SetLike for HashSet<T, S>
33where
34 T: Eq + Hash + Display + Clone,
35 S: std::hash::BuildHasher,
36{
37 type Item = T;
38
39 #[inline]
40 fn contains(&self, v: &T) -> bool {
41 Self::contains(self, v)
42 }
43
44 #[inline]
45 fn is_empty(&self) -> bool {
46 Self::is_empty(self)
47 }
48}
49
50impl<T, S> SetLike for indexmap::IndexSet<T, S>
51where
52 T: Eq + Hash + Display + Clone,
53 S: std::hash::BuildHasher,
54{
55 type Item = T;
56
57 #[inline]
58 fn contains(&self, v: &T) -> bool {
59 Self::contains(self, v)
60 }
61
62 #[inline]
63 fn is_empty(&self) -> bool {
64 Self::is_empty(self)
65 }
66}
67
68impl<T, S> SetLike for ahash::AHashSet<T, S>
69where
70 T: Eq + Hash + Display + Clone,
71 S: std::hash::BuildHasher,
72{
73 type Item = T;
74
75 #[inline]
76 fn contains(&self, v: &T) -> bool {
77 self.get(v).is_some()
78 }
79
80 #[inline]
81 fn is_empty(&self) -> bool {
82 self.len() == 0
83 }
84}
85
86pub trait MapLike {
88 type Key: Hash + Eq + Display + Clone;
89 type Value: Debug;
90
91 fn contains_key(&self, key: &Self::Key) -> bool;
92 fn is_empty(&self) -> bool;
93}
94
95impl<K, V, S> MapLike for HashMap<K, V, S>
96where
97 K: Eq + Hash + Display + Clone,
98 V: Debug,
99 S: std::hash::BuildHasher,
100{
101 type Key = K;
102 type Value = V;
103
104 #[inline]
105 fn contains_key(&self, k: &K) -> bool {
106 self.contains_key(k)
107 }
108
109 #[inline]
110 fn is_empty(&self) -> bool {
111 self.is_empty()
112 }
113}
114
115impl<K, V, S> MapLike for indexmap::IndexMap<K, V, S>
116where
117 K: Eq + Hash + Display + Clone,
118 V: Debug,
119 S: std::hash::BuildHasher,
120{
121 type Key = K;
122 type Value = V;
123
124 #[inline]
125 fn contains_key(&self, k: &K) -> bool {
126 self.get(k).is_some()
127 }
128
129 #[inline]
130 fn is_empty(&self) -> bool {
131 self.is_empty()
132 }
133}
134
135impl<K, V, S> MapLike for ahash::AHashMap<K, V, S>
136where
137 K: Eq + Hash + Display + Clone,
138 V: Debug,
139 S: std::hash::BuildHasher,
140{
141 type Key = K;
142 type Value = V;
143
144 #[inline]
145 fn contains_key(&self, k: &K) -> bool {
146 self.get(k).is_some()
147 }
148
149 #[inline]
150 fn is_empty(&self) -> bool {
151 self.len() == 0
152 }
153}