IndexedDomain

Struct IndexedDomain 

Source
pub struct IndexedDomain<T: IndexedValue> { /* private fields */ }
Expand description

An indexed collection of objects.

Contains a reverse-mapping from T to T::Index for efficient lookups of indices.

Implementations§

Source§

impl<T: IndexedValue> IndexedDomain<T>

Source

pub fn new() -> Self

Creates an empty domain,

Source

pub fn value(&self, index: T::Index) -> &T

Gets the object corresponding to index.

Panics if index is not within the domain.

Source

pub fn index(&self, value: &T) -> T::Index

Gets the index corresponding to value.

Panics if value is not within the domain.

Source

pub fn contains_value(&self, value: &T) -> bool

Returns true if value is contained in the domain.

Source

pub fn contains_index(&self, index: T::Index) -> bool

Returns true if index is contained in the domain.

Source

pub fn insert(&mut self, value: T) -> T::Index

Adds value to the domain, returning its new index.

Source

pub fn as_vec(&self) -> &IndexVec<T::Index, T>

Returns immutable access to the underlying indexed vector.

Source

pub fn len(&self) -> usize

Returns the number of elements in the domain.

Source

pub fn is_empty(&self) -> bool

Returns true if the domain is empty.

Source

pub fn ensure(&mut self, value: &T) -> T::Index

Similar to IndexedDomain::index, except it adds value to the domain if it does not exist yet.

Source

pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator<Item = &T>

Returns an iterator over all elements of the domain.

Source

pub fn indices( &self, ) -> impl DoubleEndedIterator<Item = T::Index> + ExactSizeIterator<Item = T::Index>

Returns an iterator over all indices of the domain.

Source

pub fn iter_enumerated( &self, ) -> impl DoubleEndedIterator<Item = (T::Index, &T)> + ExactSizeIterator<Item = (T::Index, &T)>

Returns an iterator over all pairs of indices and elements of the domain.

Trait Implementations§

Source§

impl<T: Clone + IndexedValue> Clone for IndexedDomain<T>
where T::Index: Clone,

Source§

fn clone(&self) -> IndexedDomain<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: IndexedValue + Debug> Debug for IndexedDomain<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: IndexedValue> Default for IndexedDomain<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: IndexedValue> From<IndexVec<<T as IndexedValue>::Index, T>> for IndexedDomain<T>

Source§

fn from(domain: IndexVec<T::Index, T>) -> Self

Creates a new domain from an indexed vector.

Consider using the FromIterator implementation if you don’t want to manually construct an IndexVec object.

Source§

impl<T: IndexedValue> FromIterator<T> for IndexedDomain<T>

Source§

fn from_iter<Iter: IntoIterator<Item = T>>(iter: Iter) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<T> Freeze for IndexedDomain<T>

§

impl<T> RefUnwindSafe for IndexedDomain<T>

§

impl<T> Send for IndexedDomain<T>
where T: Send, <T as IndexedValue>::Index: Send,

§

impl<T> Sync for IndexedDomain<T>
where T: Sync, <T as IndexedValue>::Index: Sync,

§

impl<T> Unpin for IndexedDomain<T>
where T: Unpin, <T as IndexedValue>::Index: Unpin,

§

impl<T> UnwindSafe for IndexedDomain<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.