1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Module that defines the [`SetStorage`] trait.

mod singleton;
pub use self::singleton::SingletonSetStorage;

mod boolean;
pub use self::boolean::BooleanSetStorage;

#[cfg(feature = "hashbrown")]
mod hashbrown;
#[cfg(feature = "hashbrown")]
pub use self::hashbrown::HashbrownSetStorage;

mod option;
pub use self::option::OptionSetStorage;

/// The trait defining how storage works for [`Set`][crate::Set].
///
/// # Type Arguments
///
/// - `T` is the key being stored.
pub trait SetStorage<T>: Sized {
    /// Immutable iterator over storage.
    type Iter<'this>: Iterator<Item = T>
    where
        Self: 'this;

    /// Owning iterator over the storage.
    type IntoIter: Iterator<Item = T>;

    /// Construct empty storage.
    fn empty() -> Self;

    /// Get the length of storage.
    fn len(&self) -> usize;

    /// Check if storage is empty.
    fn is_empty(&self) -> bool;

    /// This is the storage abstraction for [`Set::insert`][crate::Set::insert].
    fn insert(&mut self, value: T) -> bool;

    /// This is the storage abstraction for [`Set::contains`][crate::Set::contains].
    fn contains(&self, value: T) -> bool;

    /// This is the storage abstraction for [`Set::remove`][crate::Set::remove].
    fn remove(&mut self, value: T) -> bool;

    /// This is the storage abstraction for [`Set::retain`][crate::Set::retain].
    fn retain<F>(&mut self, f: F)
    where
        F: FnMut(T) -> bool;

    /// This is the storage abstraction for [`Set::clear`][crate::Set::clear].
    fn clear(&mut self);

    /// This is the storage abstraction for [`Set::iter`][crate::Set::iter].
    fn iter(&self) -> Self::Iter<'_>;

    /// This is the storage abstraction for [`Set::into_iter`][crate::Set::into_iter].
    fn into_iter(self) -> Self::IntoIter;
}