pub struct IndexVec<I: Idx, T> { /* private fields */ }Expand description
A dense vector indexed by ID types.
This provides O(1) access and storage for dense ID-indexed data.
Implementations§
Source§impl<I: Idx, T> IndexVec<I, T>
impl<I: Idx, T> IndexVec<I, T>
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create a new IndexVec with pre-allocated capacity.
Sourcepub fn push(&mut self, v: T) -> Result<I, IndexedVecError>
pub fn push(&mut self, v: T) -> Result<I, IndexedVecError>
Push an element and return its ID.
Returns an error if the length would exceed the maximum representable by the ID type.
Sourcepub fn get(&self, idx: I) -> Option<&T>
pub fn get(&self, idx: I) -> Option<&T>
Get an element by ID, returning None if the ID is out of bounds.
Sourcepub fn into_inner(self) -> Vec<T>
pub fn into_inner(self) -> Vec<T>
Consume this IndexVec and return the underlying Vec.
Sourcepub fn swap_remove(&mut self, index: usize) -> T
pub fn swap_remove(&mut self, index: usize) -> T
Remove an element at the specified index and return it.
Trait Implementations§
Source§impl<I, T> Deserializable for IndexVec<I, T>where
I: Idx,
T: Deserializable,
impl<I, T> Deserializable for IndexVec<I, T>where
I: Idx,
T: Deserializable,
Source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
Reads a sequence of bytes from the provided
source, attempts to deserialize these bytes
into Self, and returns the result. Read more§fn min_serialized_size() -> usize
fn min_serialized_size() -> usize
Returns the minimum serialized size for one instance of this type. Read more
§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§impl<'de, I: Idx, T> Deserialize<'de> for IndexVec<I, T>where
T: Deserialize<'de>,
impl<'de, I: Idx, T> Deserialize<'de> for IndexVec<I, T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T>
impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T>
Source§impl<I: Idx, T> IntoIterator for IndexVec<I, T>
impl<I: Idx, T> IntoIterator for IndexVec<I, T>
Source§impl<I, T> LookupByIdx<I, T> for IndexVec<I, T>where
I: Idx,
impl<I, T> LookupByIdx<I, T> for IndexVec<I, T>where
I: Idx,
Source§impl<I, T> Serializable for IndexVec<I, T>where
I: Idx,
T: Serializable,
impl<I, T> Serializable for IndexVec<I, T>where
I: Idx,
T: Serializable,
Source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
Serializes
self into bytes and writes these bytes into the target.§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
Returns an estimate of how many bytes are needed to represent self. Read more
impl<I: Eq + Idx, T: Eq> Eq for IndexVec<I, T>
impl<I: Idx, T> StructuralPartialEq for IndexVec<I, T>
Auto Trait Implementations§
impl<I, T> Freeze for IndexVec<I, T>
impl<I, T> RefUnwindSafe for IndexVec<I, T>where
I: RefUnwindSafe,
T: RefUnwindSafe,
impl<I, T> Send for IndexVec<I, T>
impl<I, T> Sync for IndexVec<I, T>
impl<I, T> Unpin for IndexVec<I, T>
impl<I, T> UnsafeUnpin for IndexVec<I, T>
impl<I, T> UnwindSafe for IndexVec<I, T>where
I: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
§impl<'a, F, I> BatchInvert<F> for I
impl<'a, F, I> BatchInvert<F> for I
§fn batch_invert(self) -> F
fn batch_invert(self) -> F
Consumes this iterator and inverts each field element (when nonzero). Zero-valued
elements are left as zero. Read more
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more