AttributeSet

Trait AttributeSet 

Source
pub trait AttributeSet: Sized + Default {
    type Item: PartialEq + Copy + Attributes;

    const MAX_COUNT: usize;
    const NONE: Self;
Show 27 methods // Required methods fn insert(&mut self, item: Self::Item) -> bool; fn try_insert(&mut self, item: Self::Item) -> Result<(), InsertError>; fn insert_or_replace_last(&mut self, item: Self::Item) -> bool; fn remove(&mut self, item: &Self::Item) -> bool; fn take(&mut self, item: &Self::Item) -> Option<Self::Item>; fn replace(&mut self, item: &Self::Item, new_item: Self::Item) -> bool; fn clear(&mut self); fn iter_attributes(&self) -> impl Iterator<Item = ItemAttribute>; fn as_slice(&self) -> &[Option<Self::Item>]; fn as_mut_slice(&mut self) -> &mut [Option<Self::Item>]; // Provided methods fn get(&self, index: usize) -> Option<&Self::Item> { ... } fn len(&self) -> usize { ... } fn contains(&self, item: &Self::Item) -> bool { ... } fn is_empty(&self) -> bool { ... } fn is_full(&self) -> bool { ... } fn capacity(&self) -> usize { ... } fn first(&self) -> Option<&Self::Item> { ... } fn last(&self) -> Option<&Self::Item> { ... } fn difference(&self, other: &Self) -> Self { ... } fn intersection(&self, other: &Self) -> Self { ... } fn is_disjoint(&self, other: &Self) -> bool { ... } fn is_subset(&self, other: &Self) -> bool { ... } fn is_superset(&self, other: &Self) -> bool { ... } fn iter(&self) -> impl Iterator<Item = &Self::Item> { ... } fn iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Item> { ... } fn retain<F>(&mut self, f: F) where F: FnMut(&Self::Item) -> bool { ... } fn extend<I: IntoIterator<Item = Self::Item>>(&mut self, iter: I) { ... }
}
Expand description

A fixed set of attributes.

Required Associated Constants§

Source

const MAX_COUNT: usize

Max number of items.

Source

const NONE: Self

An empty set.

Required Associated Types§

Source

type Item: PartialEq + Copy + Attributes

The item type.

Required Methods§

Source

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

Adds an item to the first available slot. Returns false if the set is full or already contains the value.

Source

fn try_insert(&mut self, item: Self::Item) -> Result<(), InsertError>

Same as insert, but returns a std::result::Result with descriptive error to identify why the insert failed.

Source

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

Adds an item to the first available slot. Replaces the last item in the set if the set is full. Returns false if the set already contains the value.

Source

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

Removes an item from the set. Returns whether the value was present in the set.

Source

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

Removes and returns the item in the set, if any, that is equal to the given one.

Source

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

Replaces an item in the set with a new item. false if the item was not present.

Source

fn clear(&mut self)

Clears the set.

Source

fn iter_attributes(&self) -> impl Iterator<Item = ItemAttribute>

Converts each element to an ItemAttribute.

Source

fn as_slice(&self) -> &[Option<Self::Item>]

Returns the inner storage as a slice.

Source

fn as_mut_slice(&mut self) -> &mut [Option<Self::Item>]

Returns the inner storage as a mutable slice.

Provided Methods§

Source

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

Gets an item from the set by index.

Source

fn len(&self) -> usize

Returns the number of elements in the set.

Source

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

Returns true if the set contains the given item.

Source

fn is_empty(&self) -> bool

Returns true if the set is empty.

Source

fn is_full(&self) -> bool

Returns true if the set is full, i.e., it contains the maximum number of elements.

Source

fn capacity(&self) -> usize

Gets the capacity of the set.

Source

fn first(&self) -> Option<&Self::Item>

Gets the first item in the set.

Source

fn last(&self) -> Option<&Self::Item>

Gets the last item in the set.

Source

fn difference(&self, other: &Self) -> Self

Returns the items that are in self but not in other.

Source

fn intersection(&self, other: &Self) -> Self

Returns the items that are both in self and other.

Source

fn is_disjoint(&self, other: &Self) -> bool

Returns true if self has no items in common with other. This is equivalent to checking for an empty intersection.

Source

fn is_subset(&self, other: &Self) -> bool

Returns true if the set is a subset of another, i.e., other contains at least all the values in self.

Source

fn is_superset(&self, other: &Self) -> bool

Returns true if the set is a superset of another, i.e., self contains at least all the values in other.

Source

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

Returns an iterator over the set.

Source

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

Returns a mutable iterator over the set.

Source

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

Retains only the items specified by the predicate.

Source

fn extend<I: IntoIterator<Item = Self::Item>>(&mut self, iter: I)

Extends items from an iterator into 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§