fixed_map/set/
storage.rs

1//! Module that defines the [`SetStorage`] trait.
2
3mod singleton;
4pub use self::singleton::SingletonSetStorage;
5
6mod boolean;
7pub use self::boolean::BooleanSetStorage;
8
9#[cfg(feature = "hashbrown")]
10mod hashbrown;
11#[cfg(feature = "hashbrown")]
12pub use self::hashbrown::HashbrownSetStorage;
13
14mod option;
15pub use self::option::OptionSetStorage;
16
17/// The trait defining how storage works for [`Set`][crate::Set].
18///
19/// # Type Arguments
20///
21/// - `T` is the key being stored.
22pub trait SetStorage<T>: Sized {
23    /// Immutable iterator over storage.
24    type Iter<'this>: Iterator<Item = T>
25    where
26        Self: 'this;
27
28    /// Owning iterator over the storage.
29    type IntoIter: Iterator<Item = T>;
30
31    /// Construct empty storage.
32    fn empty() -> Self;
33
34    /// Get the length of storage.
35    fn len(&self) -> usize;
36
37    /// Check if storage is empty.
38    fn is_empty(&self) -> bool;
39
40    /// This is the storage abstraction for [`Set::insert`][crate::Set::insert].
41    fn insert(&mut self, value: T) -> bool;
42
43    /// This is the storage abstraction for [`Set::contains`][crate::Set::contains].
44    fn contains(&self, value: T) -> bool;
45
46    /// This is the storage abstraction for [`Set::remove`][crate::Set::remove].
47    fn remove(&mut self, value: T) -> bool;
48
49    /// This is the storage abstraction for [`Set::retain`][crate::Set::retain].
50    fn retain<F>(&mut self, f: F)
51    where
52        F: FnMut(T) -> bool;
53
54    /// This is the storage abstraction for [`Set::clear`][crate::Set::clear].
55    fn clear(&mut self);
56
57    /// This is the storage abstraction for [`Set::iter`][crate::Set::iter].
58    fn iter(&self) -> Self::Iter<'_>;
59
60    /// This is the storage abstraction for [`Set::into_iter`][crate::Set::into_iter].
61    fn into_iter(self) -> Self::IntoIter;
62}