Struct index_vec::IndexVec [−][src]
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):
IndexVec::next_idx
,IndexSlice::last_idx
give the next and most recent index returned bypush
.IndexVec::push
returns the index the item was inserted at.
Fields
raw: Vec<T>
Our wrapped Vec.
Implementations
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
.
pub fn splice<R, It>(
&mut self,
range: R,
replace_with: It
) -> Splice<'_, <It as IntoIterator>::IntoIter> where
It: IntoIterator<Item = T>,
R: IdxRangeBounds<I>,
pub fn splice<R, It>(
&mut self,
range: R,
replace_with: It
) -> Splice<'_, <It as IntoIterator>::IntoIter> where
It: IntoIterator<Item = T>,
R: IdxRangeBounds<I>,
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
.
Get a the storage as a &[T]
Get a the storage as a &mut [T]
Equivalent to accessing our raw
field mutably, but as a function, if
that’s what you’d prefer.
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.
Forwards to the Vec::retain
implementation.
Forwards to the Vec::dedup_by_key
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]>>
Returns the underlying slice.
Returns the underlying slice.
Returns an unsafe mutable pointer to the slice’s buffer.
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_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.
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
.
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 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
IndexSlice
s with the correct index type.
Wraps the underlying slice’s chunks
iterator with one that yields
IndexSlice
s with the correct index type.
pub fn chunks_mut(
&mut self,
size: usize
) -> Map<ChunksMut<'_, T>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
pub fn chunks_mut(
&mut self,
size: usize
) -> Map<ChunksMut<'_, T>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
Wraps the underlying slice’s chunks_mut
iterator with one that yields
IndexSlice
s with the correct index type.
pub fn chunks_exact(
&self,
chunk_size: usize
) -> Map<ChunksExact<'_, T>, fn(_: &[T]) -> &IndexSlice<I, [T]>>
pub fn chunks_exact(
&self,
chunk_size: usize
) -> Map<ChunksExact<'_, T>, fn(_: &[T]) -> &IndexSlice<I, [T]>>
Wraps the underlying slice’s chunks_exact
iterator with one that
yields IndexSlice
s with the correct index type.
pub fn chunks_exact_mut(
&mut self,
chunk_size: usize
) -> Map<ChunksExactMut<'_, T>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
pub fn chunks_exact_mut(
&mut self,
chunk_size: usize
) -> Map<ChunksExactMut<'_, T>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
Wraps the underlying slice’s chunks_exact_mut
iterator with one that
yields IndexSlice
s with the correct index type.
Wraps the underlying slice’s rchunks
iterator with one that yields
IndexSlice
s with the correct index type.
pub fn rchunks_mut(
&mut self,
size: usize
) -> Map<RChunksMut<'_, T>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
pub fn rchunks_mut(
&mut self,
size: usize
) -> Map<RChunksMut<'_, T>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
Wraps the underlying slice’s rchunks_mut
iterator with one that yields
IndexSlice
s with the correct index type.
pub fn rchunks_exact(
&self,
chunk_size: usize
) -> Map<RChunksExact<'_, T>, fn(_: &[T]) -> &IndexSlice<I, [T]>>
pub fn rchunks_exact(
&self,
chunk_size: usize
) -> Map<RChunksExact<'_, T>, fn(_: &[T]) -> &IndexSlice<I, [T]>>
Wraps the underlying slice’s rchunks_exact
iterator with one that
yields IndexSlice
s with the correct index type.
pub fn rchunks_exact_mut(
&mut self,
chunk_size: usize
) -> Map<RChunksExactMut<'_, T>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
pub fn rchunks_exact_mut(
&mut self,
chunk_size: usize
) -> Map<RChunksExactMut<'_, T>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
Wraps the underlying slice’s rchunks_exact_mut
iterator with one that
yields IndexSlice
s with the correct index type.
Wraps the underlying slice’s split
iterator with one that yields
IndexSlice
s with the correct index type.
Wraps the underlying slice’s split_mut
iterator with one that yields
IndexSlice
s with the correct index type.
Wraps the underlying slice’s rsplit
iterator with one that yields
IndexSlice
s with the correct index type.
Wraps the underlying slice’s rsplit_mut
iterator with one that yields
IndexSlice
s with the correct index type.
Wraps the underlying slice’s splitn
iterator with one that yields
IndexSlice
s with the correct index type.
Wraps the underlying slice’s splitn_mut
iterator with one that yields
IndexSlice
s with the correct index type.
Wraps the underlying slice’s rsplitn
iterator with one that yields
IndexSlice
s with the correct index type.
pub fn rsplitn_mut<F: FnMut(&T) -> bool>(
&mut self,
n: usize,
f: F
) -> Map<RSplitNMut<'_, T, F>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
pub fn rsplitn_mut<F: FnMut(&T) -> bool>(
&mut self,
n: usize,
f: F
) -> Map<RSplitNMut<'_, T, F>, fn(_: &mut [T]) -> &mut IndexSlice<I, [T]>>
Wraps the underlying slice’s rsplitn_mut
iterator with one that yields
IndexSlice
s 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
Performs the conversion.
Performs the conversion.
Mutably borrows from an owned value. Read more
type Target = IndexSlice<I, [A]>
type Target = IndexSlice<I, [A]>
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
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
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Performs the conversion.
Performs the conversion.
Creates a value from an iterator. 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 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
Auto Trait Implementations
impl<I, T> RefUnwindSafe for IndexVec<I, T> where
T: RefUnwindSafe,
impl<I, T> UnwindSafe for IndexVec<I, T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more