Trait StackedSet

Source
pub trait StackedSet: Sized {
    type Item;
    type Shorten<'new>: StackedSet<Item = Self::Item> + 'new
       where Self: 'new;
    type IntoIter<'i>: Iterator<Item = &'i Self::Item> + 'i
       where Self: 'i;

    // Required methods
    fn empty() -> Self;
    fn contains_ref(&self, item: &Self::Item) -> bool;
    fn extend(&mut self, new_item: Self::Item) -> Self::Shorten<'_>;
    fn fork(&mut self) -> Self::Shorten<'_>;
    fn iter(&self) -> Self::IntoIter<'_>;

    // Provided method
    fn contains(&self, item: impl Borrow<Self::Item>) -> bool { ... }
}
Expand description

Common trait for stacked set implementations. Users are intended to define their input as impl StackedSet<Item = WhateverItemTheyNeed>, so it’s up to the user to pick the implementation

Required Associated Types§

Source

type Item

Item stored in the set

Source

type Shorten<'new>: StackedSet<Item = Self::Item> + 'new where Self: 'new

Intended to be the same type, but living for less time

Source

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

Iterator type for the set

Required Methods§

Source

fn empty() -> Self

Creates an empty set

Source

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

Checks if element is present in the set

Source

fn extend(&mut self, new_item: Self::Item) -> Self::Shorten<'_>

Adds an item to the stack, returning a new instance now “containing” the item

Note, that original instance is being exclusively borrowed, i.e.

  • new stacked set should not outlive it’s parent
  • parent itself cannot be observed while new instance lives

Once this new instance is dropped, original stack is not supposed to contain this new type

Source

fn fork(&mut self) -> Self::Shorten<'_>

Same as StackedSet::extend, but does not actually extend the stackset

Intended to be used, when you need to pass StackedSet implementor into multiple inner calls, while retaining ownership of the original one

Source

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

Returns iterator over the set, no specific order guaranteed

Provided Methods§

Source

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

Checks if element is present in the set

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.

Implementors§

Source§

impl<Collection: SetCollection> StackedSet for CollectionSet<'_, Collection>

Available on crate feature collection only.
Source§

type Item = <Collection as SetCollection>::Item

Source§

type Shorten<'new> = CollectionSet<'new, Collection> where Self: 'new

Source§

type IntoIter<'i> = <Collection as SetCollection>::IntoIter<'i> where Self: 'i

Source§

impl<Item: PartialEq> StackedSet for ConsSet<'_, Item>

Source§

type Item = Item

Source§

type Shorten<'new> = ConsSet<'new, Item> where Self: 'new

Source§

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