rustc_index::slice

Struct IndexSlice

source
#[repr(transparent)]
pub struct IndexSlice<I: Idx, T> { _marker: PhantomData<fn(_: &I)>, pub raw: [T], }
Expand description

A view into contiguous Ts, indexed by I rather than by usize.

One common pattern you’ll see is code that uses IndexVec::from_elem to create the storage needed for a particular “universe” (aka the set of all the possible keys that need an associated value) then passes that working area as &mut IndexSlice<I, T> to clarify that nothing will be added nor removed during processing (and, as a bonus, to chase fewer pointers).

Fields§

§_marker: PhantomData<fn(_: &I)>§raw: [T]

Implementations§

source§

impl<I: Idx, T> IndexSlice<I, T>

source

pub const fn empty<'a>() -> &'a Self

source

pub const fn from_raw(raw: &[T]) -> &Self

source

pub fn from_raw_mut(raw: &mut [T]) -> &mut Self

source

pub const fn len(&self) -> usize

source

pub const fn is_empty(&self) -> bool

source

pub fn next_index(&self) -> I

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

Manual bounds checks can be done using idx < slice.next_index() (as opposed to idx.index() < slice.len()).

source

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

source

pub fn iter_enumerated( &self, ) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator + '_

source

pub fn indices( &self, ) -> impl DoubleEndedIterator<Item = I> + ExactSizeIterator + Clone + 'static

source

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

source

pub fn iter_enumerated_mut( &mut self, ) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator + '_

source

pub fn last_index(&self) -> Option<I>

source

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

source

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

source

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

source

pub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T)

Returns mutable references to two distinct elements, a and b.

Panics if a == b.

source

pub fn pick3_mut(&mut self, a: I, b: I, c: I) -> (&mut T, &mut T, &mut T)

Returns mutable references to three distinct elements.

Panics if the elements are not distinct.

source§

impl<I: Idx, J: Idx> IndexSlice<I, J>

source

pub fn invert_bijective_mapping(&self) -> IndexVec<J, I>

Invert a bijective mapping, i.e. invert(map)[y] = x if map[x] = y, assuming the values in self are a permutation of 0..self.len().

This is used to go between memory_index (source field order to memory order) and inverse_memory_index (memory order to source field order). See also FieldsShape::Arbitrary::memory_index for more details.

Trait Implementations§

source§

impl<I: Idx, T> Borrow<IndexSlice<I, T>> for IndexVec<I, T>

source§

fn borrow(&self) -> &IndexSlice<I, T>

Immutably borrows from an owned value. Read more
source§

impl<I: Idx, T> BorrowMut<IndexSlice<I, T>> for IndexVec<I, T>

source§

fn borrow_mut(&mut self) -> &mut IndexSlice<I, T>

Mutably borrows from an owned value. Read more
source§

impl<I: Idx, T: Debug> Debug for IndexSlice<I, T>

source§

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

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

impl<I: Idx, T> Default for &IndexSlice<I, T>

source§

fn default() -> Self

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

impl<I: Idx, T> Default for &mut IndexSlice<I, T>

source§

fn default() -> Self

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

impl<I: Hash + Idx, T: Hash> Hash for IndexSlice<I, T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
source§

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

source§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: I) -> &T

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

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

source§

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

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

impl<'a, I: Idx, T> IntoIterator for &'a IndexSlice<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) -> Iter<'a, T>

Creates an iterator from a value. Read more
source§

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

source§

type Item = &'a mut T

The type of the elements being iterated over.
source§

type IntoIter = IterMut<'a, T>

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

fn into_iter(self) -> IterMut<'a, T>

Creates an iterator from a value. Read more
source§

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

source§

fn eq(&self, other: &IndexSlice<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: Idx, T: Clone> ToOwned for IndexSlice<I, T>

source§

type Owned = IndexVec<I, T>

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> IndexVec<I, T>

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

fn clone_into(&self, target: &mut IndexVec<I, T>)

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

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

source§

impl<I: Idx, T> Send for IndexSlice<I, T>
where T: Send,

source§

impl<I: Idx, T> StructuralPartialEq for IndexSlice<I, T>

Auto Trait Implementations§

§

impl<I, T> Freeze for IndexSlice<I, T>
where T: Freeze,

§

impl<I, T> RefUnwindSafe for IndexSlice<I, T>
where T: RefUnwindSafe,

§

impl<I, T> !Sized for IndexSlice<I, T>

§

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

§

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

§

impl<I, T> UnwindSafe for IndexSlice<I, T>
where 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
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

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

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.