Skip to main content

collect_failable/impls/sets/
hash_set.rs

1use core::hash::{BuildHasher, Hash};
2use std::collections::HashSet;
3
4use fluent_result::bool::dbg::Expect;
5
6crate::impls::macros::impl_try_from_iter_via_try_extend_one!(
7    type: HashSet<T, S> where [T: Eq + Hash, S: BuildHasher + Default] of T;
8    ctor: |iter| HashSet::with_capacity_and_hasher(iter.size_hint().0, S::default())
9);
10
11crate::impls::macros::impl_try_extend_via_try_extend_one!(
12    type: HashSet<T, S> where [T: Eq + Hash, S: BuildHasher + Clone] of T;
13    reserve: |set, iter| set.reserve(iter.size_hint().0)
14);
15
16crate::impls::macros::impl_try_extend_safe_for_colliding_type!(
17    type: HashSet<T, S> where [T: Eq + Hash, S: BuildHasher + Clone] of T;
18    build_staging: |iter, set| HashSet::with_capacity_and_hasher(iter.size_hint().0, set.hasher().clone());
19    contains: HashSet::contains
20);
21
22crate::impls::macros::impl_try_extend_one_for_colliding_type!(
23    type: HashSet<T, S> where [T: Eq + Hash, S: BuildHasher] of T;
24    contains: HashSet::contains;
25    insert: |set, item| set.insert(item).expect_true("insert should succeed after contains check")
26);