Struct indexical::IndexedDomain
source · 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>
impl<T: IndexedValue> IndexedDomain<T>
sourcepub fn new(domain: IndexVec<T::Index, T>) -> Self
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.
sourcepub fn value(&self, index: T::Index) -> &T
pub fn value(&self, index: T::Index) -> &T
Gets the object corresponding to index
.
Panics if index
is not within the domain.
sourcepub fn index(&self, value: &T) -> T::Index
pub fn index(&self, value: &T) -> T::Index
Gets the index corresponding to value
.
Panics if value
is not within the domain.
sourcepub fn insert(&mut self, value: T) -> T::Index
pub fn insert(&mut self, value: T) -> T::Index
Adds value
to the domain, returning its new index.
sourcepub fn as_vec(&self) -> &IndexVec<T::Index, T>
pub fn as_vec(&self) -> &IndexVec<T::Index, T>
Returns immutable access to the underlying indexed vector.
sourcepub fn ensure(&mut self, value: &T) -> T::Index
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>
impl<T: IndexedValue + Debug> Debug for IndexedDomain<T>
source§impl<T: IndexedValue> FromIterator<T> for IndexedDomain<T>
impl<T: IndexedValue> FromIterator<T> for IndexedDomain<T>
source§fn from_iter<Iter: IntoIterator<Item = T>>(iter: Iter) -> Self
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>
impl<T> Sync for IndexedDomain<T>
impl<T> Unpin for IndexedDomain<T>
impl<T> UnwindSafe for IndexedDomain<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more