Skip to main content

CollectionSet

Trait CollectionSet 

Source
pub trait CollectionSet: CollectionBase {
    // Required methods
    fn contains(&self, item: &Self::Item) -> bool;
    fn get(&self, item: &Self::Item) -> Option<&Self::Item>;
    fn iter(&self) -> impl Iterator<Item = &Self::Item>;
    fn insert(&mut self, item: Self::Item) -> bool;
    fn replace(&mut self, item: Self::Item) -> Option<Self::Item>;
    fn remove(&mut self, item: &Self::Item) -> bool;
    fn take(&mut self, item: &Self::Item) -> Option<Self::Item>;
    fn retain(&mut self, f: impl FnMut(&Self::Item) -> bool);
}
Expand description

Trait implemented by set collections.

Required Methods§

Source

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

Checks whether an equal item is present in the set.

Source

fn get(&self, item: &Self::Item) -> Option<&Self::Item>

Returns a reference to the stored item equal to the given item.

Source

fn iter(&self) -> impl Iterator<Item = &Self::Item>

Returns an iterator over the set’s items.

Source

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

Inserts an item, returning whether the set did not already contain it.

Source

fn replace(&mut self, item: Self::Item) -> Option<Self::Item>

Inserts an item or replaces an equal one, returning the previous item if any.

Source

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

Removes an equal item, returning whether it was present.

Source

fn take(&mut self, item: &Self::Item) -> Option<Self::Item>

Removes an equal item and returns the stored item if present.

Source

fn retain(&mut self, f: impl FnMut(&Self::Item) -> bool)

Retains only the items specified by the predicate.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Eq + Hash, S: BuildHasher, A: Allocator> CollectionSet for HashSet<T, S, A>

Available on crate feature hashbrown only.
Source§

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

Source§

fn get(&self, item: &Self::Item) -> Option<&Self::Item>

Source§

fn iter(&self) -> impl Iterator<Item = &Self::Item>

Source§

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

Source§

fn replace(&mut self, item: Self::Item) -> Option<Self::Item>

Source§

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

Source§

fn take(&mut self, item: &Self::Item) -> Option<Self::Item>

Source§

fn retain(&mut self, f: impl FnMut(&Self::Item) -> bool)

Source§

impl<T: Eq + Hash, S: BuildHasher> CollectionSet for HashSet<T, S>

Available on crate feature std only.
Source§

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

Source§

fn get(&self, item: &Self::Item) -> Option<&Self::Item>

Source§

fn iter(&self) -> impl Iterator<Item = &Self::Item>

Source§

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

Source§

fn replace(&mut self, item: Self::Item) -> Option<Self::Item>

Source§

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

Source§

fn take(&mut self, item: &Self::Item) -> Option<Self::Item>

Source§

fn retain(&mut self, f: impl FnMut(&Self::Item) -> bool)

Source§

impl<T: Eq + Hash, S: BuildHasher> CollectionSet for IndexSet<T, S>

Available on crate feature indexmap only.
Source§

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

Source§

fn get(&self, item: &Self::Item) -> Option<&Self::Item>

Source§

fn iter(&self) -> impl Iterator<Item = &Self::Item>

Source§

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

Source§

fn replace(&mut self, item: Self::Item) -> Option<Self::Item>

Source§

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

Source§

fn take(&mut self, item: &Self::Item) -> Option<Self::Item>

Source§

fn retain(&mut self, f: impl FnMut(&Self::Item) -> bool)

Source§

impl<T: Ord> CollectionSet for BTreeSet<T>

Available on crate feature alloc only.
Source§

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

Source§

fn get(&self, item: &Self::Item) -> Option<&Self::Item>

Source§

fn iter(&self) -> impl Iterator<Item = &Self::Item>

Source§

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

Source§

fn replace(&mut self, item: Self::Item) -> Option<Self::Item>

Source§

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

Source§

fn take(&mut self, item: &Self::Item) -> Option<Self::Item>

Source§

fn retain(&mut self, f: impl FnMut(&Self::Item) -> bool)

Implementors§