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

An indexed collection of objects, implemented with an IndexVec.

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(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

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(&self, value: &T) -> bool

Returns true if value 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.

Trait Implementations§

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> 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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.