Struct index_vec::IndexSlice [−][src]
Expand description
A slice that only accepts indices of a specific type. Note that the intended
usage is as IndexSlice<I, [T]>
.
This is a thin wrapper around a [T]
, to the point where the backing 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 slice itself.
Some notes on the APIs
-
Most of the Slice APIs are present.
- Any that aren’t can be trivially accessed on the underlying
raw
field, which is public.
- Any that aren’t can be trivially accessed on the underlying
-
Apis that take or return usizes referring to the positions of items were replaced with ones that take Idx.
-
Apis that take
R: RangeBounds<usize>
take anIdxRangeBounds<I>
, which is basically aRangeBounds<I>
. -
Apis that take
SliceIndex<usize>
take anIdxSliceIndex<I>
, which is basically aSliceIndex<I>
. -
Most iterator functions where
the_iter().enumerate()
would refer to indices have been given_enumerated
variants. E.g.IndexSlice::iter_enumerated
, etc. This is becausev.iter().enumerate()
would be(usize, &T)
, but you want(I, &T)
.
The following extensions are added:
IndexSlice::indices
: an Iterator over the indices of typeI
.- Various
enumerated
iterators mentioned earlier IndexSlice::position
,IndexSlice::rposition
asself.iter().position()
will return aOption<usize>
Fields
raw: T
Implementations
Construct a new IdxSlice by wrapping an existing slice.
Construct a new mutable IdxSlice by wrapping an existing mutable slice.
Construct a new IdxSlice by wrapping an existing slice.
Construct a new mutable IdxSlice by wrapping an existing mutable slice.
Converts self
into a vector without clones or allocation.
The resulting vector can be converted back into a box via
IndexVec<I, T>
’s into_boxed_slice
method.
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.
Create a IdxSlice from its pointer and length.
Safety
This is equivalent to core::slice::from_raw_parts
and has the same
safety caveats.
Create a mutable IdxSlice from its pointer and length.
Safety
This is equivalent to core::slice::from_raw_parts_mut
and has the same
safety caveats.
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
Performs the conversion.
Performs the conversion.
Performs the conversion.
impl<'a, 'b, A, B, I: Idx> PartialEq<&'b mut [B]> for IndexSlice<I, [A]> where
A: PartialEq<B>,
impl<'a, 'b, A, B, I: Idx> PartialEq<&'b mut [B]> for IndexSlice<I, [A]> where
A: PartialEq<B>,
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: ?Sized> RefUnwindSafe for IndexSlice<I, T> where
T: RefUnwindSafe,
impl<I, T: ?Sized> Send for IndexSlice<I, T> where
T: Send,
impl<I, T: ?Sized> Sync for IndexSlice<I, T> where
T: Sync,
impl<I, T: ?Sized> Unpin for IndexSlice<I, T> where
T: Unpin,
impl<I, T: ?Sized> UnwindSafe for IndexSlice<I, T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more