Trait SetCollection

Source
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 { ... }
}
Available on crate feature 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§

Source

type Item

Element type stored in the collection.

Source

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).

Source

type IntoIter<'i>: Iterator<Item = &'i Self::Item> where Self: 'i

Type of iterator over item references.

Required Methods§

Source

fn new() -> Self

Creates an empty collection.

Source

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.

Source

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.

Source

fn remove(&mut self, present_item: Self::ExtendMemory)

Removes an element from the collection represented by SetCollection::ExtendMemory instance.

Source

fn iter(&self) -> Self::IntoIter<'_>

Creates iterator over item references.

Provided Methods§

Source

fn contains(&self, item: impl Borrow<Self::Item>) -> bool

Checks if the collection contains a certain element.

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>

Source§

type Item = Item

Available on crate feature collection only.
Source§

type ExtendMemory = Item

Available on crate feature collection only.
Source§

type IntoIter<'i> = Iter<'i, Item> where Self: 'i

Available on crate feature collection only.
Source§

fn new() -> Self

Available on crate feature collection only.
Source§

fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory

Available on crate feature collection only.
Source§

fn contains_ref(&self, item: &Self::Item) -> bool

Available on crate feature collection only.
Source§

fn remove(&mut self, present_item: Self::ExtendMemory)

Available on crate feature collection only.
Source§

fn iter(&self) -> Self::IntoIter<'_>

Available on crate feature collection only.
Source§

impl<Item: Ord + PartialEq + Clone> SetCollection for BTreeSet<Item>

Source§

type Item = Item

Available on crate feature collection only.
Source§

type ExtendMemory = Item

Available on crate feature collection only.
Source§

type IntoIter<'i> = Iter<'i, Item> where Self: 'i

Available on crate feature collection only.
Source§

fn new() -> Self

Available on crate feature collection only.
Source§

fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory

Available on crate feature collection only.
Source§

fn contains_ref(&self, item: &Self::Item) -> bool

Available on crate feature collection only.
Source§

fn remove(&mut self, present_item: Self::ExtendMemory)

Available on crate feature collection only.
Source§

fn iter(&self) -> Self::IntoIter<'_>

Available on crate feature collection only.
Source§

impl<Item: PartialEq> SetCollection for Vec<Item>

Source§

type Item = Item

Available on crate feature collection only.
Source§

type ExtendMemory = ()

Available on crate feature collection only.
Source§

type IntoIter<'i> = Iter<'i, Item> where Self: 'i

Available on crate feature collection only.
Source§

fn new() -> Self

Available on crate feature collection only.
Source§

fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory

Available on crate feature collection only.
Source§

fn contains_ref(&self, item: &Self::Item) -> bool

Available on crate feature collection only.
Source§

fn remove(&mut self, _present_item: Self::ExtendMemory)

Available on crate feature collection only.
Source§

fn iter(&self) -> Self::IntoIter<'_>

Available on crate feature collection only.

Implementors§