pub trait SetCollection {
type Item;
type ExtendMemory;
type IntoIter<'i>: Iterator<Item = &'i Self::Item>
where Self: 'i;
// Required methods
fn new() -> Self;
fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory;
fn contains_ref(&self, item: &Self::Item) -> bool;
fn remove(&mut self, present_item: Self::ExtendMemory);
fn iter(&self) -> Self::IntoIter<'_>;
// Provided method
fn contains(&self, item: impl Borrow<Self::Item>) -> bool { ... }
}
collection
only.Expand description
Kind of interface a “collection” should expose for StackedSet
implementation to be built on top of it.
To get a StackedSet
implementor, just wrap your collection into CollectionSet
. Original collection will still be available via Deref
/Borrow
/AsRef
.
Required Associated Types§
Sourcetype ExtendMemory
type ExtendMemory
A some sort of memory that can be used to remove the item back. Some implementations (like Vec
may want to make this a unit type, if the item to remove is somehow known through collection structure).
Required Methods§
Sourcefn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory
fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory
Extends the collection, creating instance of ExtendMemory
to later remove this element. Note that implementation should not care about item previously existing, as CollectionSet
checks for new_item
not being present in the collection prior to this call.
Sourcefn contains_ref(&self, item: &Self::Item) -> bool
fn contains_ref(&self, item: &Self::Item) -> bool
Checks if the collection contains a certain element. Only accepts in a core reference, check SetCollection::contains
method if more flexibility is needed.
Sourcefn remove(&mut self, present_item: Self::ExtendMemory)
fn remove(&mut self, present_item: Self::ExtendMemory)
Removes an element from the collection represented by SetCollection::ExtendMemory
instance.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<Item: Clone + Eq + Hash, S: BuildHasher + Default> SetCollection for HashSet<Item, S>
impl<Item: Clone + Eq + Hash, S: BuildHasher + Default> SetCollection for HashSet<Item, S>
Source§type ExtendMemory = Item
type ExtendMemory = Item
collection
only.Source§fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory
fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory
collection
only.Source§fn contains_ref(&self, item: &Self::Item) -> bool
fn contains_ref(&self, item: &Self::Item) -> bool
collection
only.Source§fn remove(&mut self, present_item: Self::ExtendMemory)
fn remove(&mut self, present_item: Self::ExtendMemory)
collection
only.Source§impl<Item: Ord + PartialEq + Clone> SetCollection for BTreeSet<Item>
impl<Item: Ord + PartialEq + Clone> SetCollection for BTreeSet<Item>
Source§type ExtendMemory = Item
type ExtendMemory = Item
collection
only.Source§fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory
fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory
collection
only.Source§fn contains_ref(&self, item: &Self::Item) -> bool
fn contains_ref(&self, item: &Self::Item) -> bool
collection
only.Source§fn remove(&mut self, present_item: Self::ExtendMemory)
fn remove(&mut self, present_item: Self::ExtendMemory)
collection
only.Source§impl<Item: PartialEq> SetCollection for Vec<Item>
impl<Item: PartialEq> SetCollection for Vec<Item>
Source§type ExtendMemory = ()
type ExtendMemory = ()
collection
only.Source§fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory
fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory
collection
only.Source§fn contains_ref(&self, item: &Self::Item) -> bool
fn contains_ref(&self, item: &Self::Item) -> bool
collection
only.Source§fn remove(&mut self, _present_item: Self::ExtendMemory)
fn remove(&mut self, _present_item: Self::ExtendMemory)
collection
only.