[][src]Struct index_vec::IndexVec

pub struct IndexVec<I: Idx, T> {
    pub vec: Vec<T>,
    // some fields omitted
}

A Vec that only accepts indices of a specific type.

This is a thin wrapper around Vec, to the point where the backing vec is a public property. This is in part because I know this API is not a complete mirror of Vec's (patches welcome). In the worst case, you can always do what you need to the Vec itself.

Fields

vec: Vec<T>

Our wrapped Vec.

Methods

impl<I: Idx, T> IndexVec<I, T>[src]

pub fn new() -> Self[src]

Construct a new IndexVec.

pub fn from_vec(vec: Vec<T>) -> Self[src]

Construct a IndexVec from a Vec<T>.

Panics if it's length is too large for our index type.

pub fn with_capacity(capacity: usize) -> Self[src]

Construct an IndexVec that can hold at least capacity items before reallocating. See Vec::with_capacity.

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

Get a the storage as a &[T]

pub fn as_mut_slice(&mut self) -> &mut [T][src]

Get a the storage as a &mut [T]

pub fn push(&mut self, d: T) -> I[src]

Push a new item onto the vector, and return it's index.

pub fn pop(&mut self) -> Option<T>[src]

Pops the last item off, returning it. See Vec::pop.

pub fn len(&self) -> usize[src]

Returns the length of our vector.

pub fn is_empty(&self) -> bool[src]

Returns true if we're empty.

pub fn into_iter_enumerated(
    self
) -> Map<Enumerate<IntoIter<T>>, fn(_: (usize, T)) -> (I, T)>
[src]

Similar to self.into_iter().enumerate() but with indices of I and not usize.

pub fn iter(&self) -> Iter<T>[src]

Get a iterator over reverences to our values.

pub fn iter_enumerated(
    &self
) -> Map<Enumerate<Iter<T>>, fn(_: (usize, &T)) -> (I, &T)>
[src]

Similar to self.iter().enumerate() but with indices of I and not usize.

pub fn indices(&self) -> Map<Range<usize>, fn(_: usize) -> I>[src]

Get an interator over all our indices.

pub fn iter_mut(&mut self) -> IterMut<T>[src]

Get a iterator over mut reverences to our values.

pub fn iter_mut_enumerated(
    &mut self
) -> Map<Enumerate<IterMut<T>>, fn(_: (usize, &mut T)) -> (I, &mut T)>
[src]

Similar to self.iter_mut().enumerate() but with indices of I and not usize.

pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> Drain<T>[src]

Return an iterator that removes the items from the requested range. See Vec::drain.

pub fn drain_enumerated<R: RangeBounds<usize>>(
    &mut self,
    range: R
) -> Map<Enumerate<Drain<T>>, fn(_: (usize, T)) -> (I, T)>
[src]

Similar to self.drain(r).enumerate() but with indices of I and not usize.

pub fn last(&self) -> Option<I>[src]

Return the index of the last element, if we are not empty.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the vector as much as possible.

pub fn swap(&mut self, a: I, b: I)[src]

Swaps two elements in our vector.

pub fn truncate(&mut self, a: usize)[src]

Shortens the vector, keeping the first len elements and dropping the rest. See Vec::truncate

pub fn clear(&mut self)[src]

Clear our vector. See Vec::clear.

pub fn reserve(&mut self, c: usize)[src]

Reserve capacity for c more elements. See Vec::reserve

pub fn next_idx(&self) -> I[src]

Gives the next index that will be assigned when push is called.

pub fn last_idx(&self) -> I[src]

Return the index of the last element, or panic.

pub fn get(&self, index: I) -> Option<&T>[src]

Get a ref to the item at the provided index, or None for out of bounds.

pub fn get_mut(&mut self, index: I) -> Option<&mut T>[src]

Get a mut ref to the item at the provided index, or None for out of bounds

pub fn resize(&mut self, new_len: usize, value: T) where
    T: Clone
[src]

Resize ourselves in-place to new_len. See Vec::resize.

pub fn resize_with<F: FnMut() -> T>(&mut self, new_len: usize, f: F)[src]

Resize ourselves in-place to new_len. See Vec::resize_with.

pub fn append(&mut self, other: &mut Self)[src]

Moves all the elements of other into Self, leaving other empty. See Vec::append.

pub fn split_off(&mut self, idx: I) -> Self[src]

Splits the collection into two at the given index. See Vec::split_off.

pub fn remove(&mut self, index: I) -> T[src]

Remove the item at index. See Vec::remove.

pub fn insert(&mut self, index: I, element: T)[src]

Insert an item at index. See Vec::insert.

pub fn swap_remove(&mut self, index: I) -> T[src]

Remove the item at index without maintaining order. See Vec::swap_remove.

Call slice::binary_search converting the indices it gives us back as needed.

pub fn extend_from_slice(&mut self, other: &[T]) where
    T: Clone
[src]

Append all items in the slice to the end of our vector.

See Vec::extend_from_slice.

Trait Implementations

impl<I: Idx, T> From<Vec<T>> for IndexVec<I, T>[src]

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

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

impl<I: Hash + Idx, T: Hash> Hash for IndexVec<I, T>[src]

impl<I: Idx, T> Index<I> for IndexVec<I, T>[src]

type Output = T

The returned type after indexing.

impl<I: Idx, T> IndexMut<I> for IndexVec<I, T>[src]

impl<I: Idx, T: Debug> Debug for IndexVec<I, T>[src]

impl<I: Idx, T> FromIterator<T> for IndexVec<I, T>[src]

impl<I: Idx, T> Send for IndexVec<I, T> where
    T: Send
[src]

impl<I: Idx, T> IntoIterator for IndexVec<I, T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

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

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, I: Idx, T> IntoIterator for &'a mut IndexVec<I, T>[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

impl<I: Idx, T> Extend<T> for IndexVec<I, T>[src]

impl<'a, I: Idx, T: 'a + Copy> Extend<&'a T> for IndexVec<I, T>[src]

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

impl<I: Idx, T> Default for IndexVec<I, T>[src]

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.