1#![no_std] #![cfg_attr(docsrs, feature(doc_cfg))]
3#![cfg_attr(any(docsrs, all(feature = "cons", feature = "collection")), doc = include_str!("../README.md"))]
4#![cfg_attr(
5 not(any(docsrs, all(feature = "cons", feature = "collection"))),
6 doc = "(no docs here)"
7)]
8
9use core::borrow::Borrow;
10
11#[cfg(feature = "std-hash")]
12extern crate std;
13
14#[cfg(any(feature = "alloc-vec", feature = "alloc-tree"))]
15extern crate alloc;
16
17#[cfg(feature = "collection")]
19#[cfg_attr(docsrs, doc(cfg(feature = "collection")))]
20pub mod collection;
21
22#[cfg(feature = "cons")]
23#[doc(hidden)]
24mod cons;
25
26#[cfg(feature = "alloc-vec")]
27#[doc(hidden)]
28mod alloc_vec;
29
30#[cfg(feature = "alloc-tree")]
31#[doc(hidden)]
32mod alloc_tree;
33
34#[cfg(feature = "std-hash")]
35#[doc(hidden)]
36mod std_hash;
37
38pub trait StackedSet: Sized {
40 type Item;
42
43 #[must_use = "Creating empty set is usually a no-op"]
45 fn empty() -> Self;
46
47 fn contains(&self, item: impl Borrow<Self::Item>) -> bool {
49 self.contains_ref(item.borrow())
50 }
51
52 #[must_use = "Checking for presence does not change set contents"]
54 fn contains_ref(&self, item: &Self::Item) -> bool;
55
56 type Shorten<'new>: StackedSet<Item = Self::Item> + 'new
58 where
59 Self: 'new;
60
61 #[must_use = "Provided value is only contained in a set returned form this call. Despite requiring exclusive borrow, original set is should not be expected to change. Check documentation for more details."]
69 fn extend(&mut self, new_item: Self::Item) -> Self::Shorten<'_>;
70
71 #[must_use = "Despite requiring exclusive borrow, original set is should not be expected to change. Check documentation for more details."]
75 fn fork(&mut self) -> Self::Shorten<'_>;
76
77 type IntoIter<'i>: Iterator<Item = &'i Self::Item> + 'i
79 where
80 Self: 'i;
81
82 fn iter(&self) -> Self::IntoIter<'_>;
84}
85
86#[cfg(feature = "cons")]
87#[cfg_attr(docsrs, doc(cfg(feature = "cons")))]
88pub use cons::ConsSet as StackCons;
89
90#[cfg(feature = "alloc-vec")]
91#[cfg_attr(docsrs, doc(cfg(feature = "alloc-vec")))]
92pub use alloc_vec::Vec as AllocVec;
93
94#[cfg(feature = "alloc-tree")]
95#[cfg_attr(docsrs, doc(cfg(feature = "alloc-tree")))]
96pub use alloc_tree::TreeSet as AllocTree;
97
98#[cfg(feature = "std-hash")]
99#[cfg_attr(docsrs, doc(cfg(feature = "std-hash")))]
100pub use std_hash::Hash as StdHash;
101
102#[cfg(test)]
103mod tests;