Skip to main content

IndexVec

Struct IndexVec 

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

Source

pub fn new() -> Self

Create a new empty IndexVec.

Source

pub fn with_capacity(n: usize) -> Self

Create a new IndexVec with pre-allocated capacity.

Source

pub fn len(&self) -> usize

Get the number of elements in the IndexVec.

Source

pub fn is_empty(&self) -> bool

Check if the IndexVec is empty.

Source

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.

Source

pub fn get(&self, idx: I) -> Option<&T>

Get an element by ID, returning None if the ID is out of bounds.

Source

pub fn as_slice(&self) -> &[T]

Get a slice of all elements.

Source

pub fn into_inner(self) -> Vec<T>

Consume this IndexVec and return the underlying Vec.

Source

pub fn swap_remove(&mut self, index: usize) -> T

Remove an element at the specified index and return it.

Source

pub fn contains(&self, item: &T) -> bool
where T: PartialEq,

Check if this IndexVec contains a specific element.

Source

pub fn iter(&self) -> Iter<'_, T>

Get an iterator over the elements in this IndexVec.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Get a mutable iterator over the elements in this IndexVec.

Trait Implementations§

Source§

impl<I: Clone + Idx, T: Clone> Clone for IndexVec<I, T>

Source§

fn clone(&self) -> IndexVec<I, 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<I: Debug + Idx, T: Debug> Debug for IndexVec<I, T>

Source§

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

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

impl<I: Idx, T> Default for IndexVec<I, T>

Source§

fn default() -> Self

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

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>

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

Returns the minimum serialized size for one instance of this type. Read more
§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
§

fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>

Deserializes Self from bytes with a byte budget limit. Read more
Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<I: Idx, T> Index<I> for IndexVec<I, T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<I: Idx, T> IndexMut<I> for IndexVec<I, T>

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<I: Idx, T> IntoIterator for IndexVec<I, T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<I, T> LookupByIdx<I, T> for IndexVec<I, T>
where I: Idx,

Source§

fn get(&self, id: I) -> Option<&T>

Get the value for the given ID.
Source§

impl<I: PartialEq + Idx, T: PartialEq> PartialEq for IndexVec<I, T>

Source§

fn eq(&self, other: &IndexVec<I, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<I, T> Serializable for IndexVec<I, T>
where I: Idx, T: Serializable,

Source§

fn write_into<W: ByteWriter>(&self, target: &mut W)

Serializes self into bytes and writes these bytes into the target.
§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
Source§

impl<I: Idx, T> Serialize for IndexVec<I, T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<I: Idx, T> TryFrom<Vec<T>> for IndexVec<I, T>

Source§

fn try_from(raw: Vec<T>) -> Result<Self, Self::Error>

Create an IndexVec from a Vec.

Returns an error if the Vec length exceeds u32::MAX.

Source§

type Error = IndexedVecError

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

impl<I: Eq + Idx, T: Eq> Eq for IndexVec<I, T>

Source§

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>

§

impl<I, T> Send for IndexVec<I, T>
where I: Send, T: Send,

§

impl<I, T> Sync for IndexVec<I, T>
where I: Sync, T: Sync,

§

impl<I, T> Unpin for IndexVec<I, T>
where I: Unpin, T: Unpin,

§

impl<I, T> UnsafeUnpin for IndexVec<I, T>

§

impl<I, T> UnwindSafe for IndexVec<I, T>
where I: UnwindSafe, T: UnwindSafe,

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
§

impl<'a, F, I> BatchInvert<F> for I
where F: Field + ConstantTimeEq, I: IntoIterator<Item = &'a mut 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> 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,