pub struct IndexVec<I, T> where
    I: Idx
{ pub raw: Vec<T, Global>, /* private fields */ }
Expand description

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 (called raw). 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.

Note that this implements Deref/DerefMut to IndexSlice, and so all the methods on IndexSlice are available as well. See it’s documentation for some further information.

The following extensions to the Vec APIs are added (in addition to the ones mentioned in IndexSlice’s documentation):

Fields

raw: Vec<T, Global>

Our wrapped Vec.

Implementations

Construct a new IndexVec.

Construct a IndexVec from a Vec<T>.

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

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

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

Creates a splicing iterator that replaces the specified range in the vector with the given replace_with iterator and yields the removed items. See Vec::splice

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

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

Get a the storage as a &[T]

Get a the storage as a &mut [T]

Equivalent to accessing our raw field, but as a function.

Equivalent to accessing our raw field mutably, but as a function, if that’s what you’d prefer.

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

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

Converts the vector into an owned IdxSlice, dropping excess capacity.

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

See also IndexVec::drain_enumerated, which gives you indices (of the correct type) as you iterate.

Shrinks the capacity of the vector as much as possible.

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

Clear our vector. See Vec::clear.

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

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

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

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

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

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

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

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

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

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

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

See Vec::extend_from_slice.

Forwards to the Vec::retain implementation.

Forwards to the Vec::dedup_by_key implementation.

Forwards to the Vec::dedup implementation.

Forwards to the Vec::dedup_by implementation.

Get a IndexSlice over this vector. See as_raw_slice for converting to a &[T] (or access self.raw).

Get a mutable IndexSlice over this vector. See as_raw_slice_mut for converting to a &mut [T] (or access self.raw).

Methods from Deref<Target = IndexSlice<I, [A]>>

Copies self into a new IndexVec.

Returns the underlying slice.

Returns the underlying slice.

Returns an unsafe mutable pointer to the slice’s buffer.

Returns an unsafe pointer to the slice’s buffer.

Return the index of the last element, or panic.

Returns the length of our slice.

Returns the length of our slice as an I.

Returns true if we’re empty.

Get a iterator over reverences to our values.

See also IndexSlice::iter_enumerated, which gives you indices (of the correct type) as you iterate.

Get a iterator over mut reverences to our values.

See also IndexSlice::iter_mut_enumerated, which gives you indices (of the correct type) as you iterate.

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

Get an interator over all our indices.

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

Forwards to the slice’s sort implementation.

Forwards to the slice’s sort_by implementation.

Forwards to the slice’s sort_by_key implementation.

Forwards to the slice’s sort_by_cached_key implementation.

Forwards to the slice’s sort_unstable implementation.

Forwards to the slice’s sort_unstable_by implementation.

Forwards to the slice’s sort_unstable_by_key implementation.

Forwards to the slice’s ends_with implementation.

Forwards to the slice’s starts_with implementation.

Forwards to the slice’s contains implementation.

Forwards to the slice’s reverse implementation.

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

Binary searches this sorted vec with a comparator function, converting the indices it gives us back to our Idx type.

Copies all elements from src into self, using a memcpy.

Copies the elements from src into self.

Swaps all elements in self with those in other.

Binary searches this sorted vec with a key extraction function, converting the indices it gives us back to our Idx type.

Searches for an element in an iterator, returning its index. This is equivalent to Iterator::position, but returns I and not usize.

Searches for an element in an iterator from the right, returning its index. This is equivalent to Iterator::position, but returns I and not usize.

Swaps two elements in our vector.

Divides our slice into two at an index.

Divides our slice into two at an index.

Rotates our data in-place such that the first mid elements of the slice move to the end while the last self.len() - mid elements move to the front

Rotates our data in-place such that the first self.len() - k elements of the slice move to the end while the last k elements move to the front

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

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

Return the the first element, if we are not empty.

Return the the first element, if we are not empty.

Copies elements from one part of the slice to another part of itself, using a memmove.

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

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

Wraps the underlying slice’s windows iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s chunks iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s chunks_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s chunks_exact iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s chunks_exact_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rchunks iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rchunks_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rchunks_exact iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rchunks_exact_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s split iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s split_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rsplit iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rsplit_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s splitn iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s splitn_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rsplitn iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rsplitn_mut iterator with one that yields IndexSlices with the correct index type.

Returns the first and all the rest of the elements of the slice, or None if it is empty.

Returns the first and all the rest of the elements of the slice, or None if it is empty.

Returns the last and all the rest of the elements of the slice, or None if it is empty.

Returns the last and all the rest of the elements of the slice, or None if it is empty.

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Creates a value from an iterator. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Use this to cast from one trait object type to another. Read more

Use this to upcast a trait to one of its supertraits. Read more

Use this to cast from one trait object type to another. This method is more customizable than the dyn_cast method. Here you can also specify the “source” trait from which the cast is defined. This can for example allow using casts from a supertrait of the current trait object. Read more

Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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