luminos_contracts/support/interacts_with_data/contains/
hashset.rs1use std::{collections::HashSet, hash::BuildHasher};
2
3use super::super::{Contains, InteractsWithData, IntoData};
4
5impl<K: Eq + std::hash::Hash, V: BuildHasher> Contains<K> for HashSet<K, V> {
6 fn contains_item(&self, key: &K) -> bool {
7 self.contains(key)
8 }
9}
10
11impl<K: Eq + std::hash::Hash, V: BuildHasher> InteractsWithData for HashSet<K, V> {
12 type Value = HashSet<K, V>;
13 type Item = K;
14
15 fn data(&self) -> &Self::Value {
16 self
17 }
18}
19
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24
25 #[test]
26 fn test_hashset_interacts_with_data() {
27 let mut map = HashSet::new();
28 map.insert("a");
29 map.insert("b");
30
31 let expected_map = HashSet::from(["a", "b"]);
32 assert_eq!(map.all(), expected_map);
33
34 assert!(map.exists(&"b"));
35 assert!(!map.exists(&"c"));
36 }
37}