IndexSlice in rustc_index - Rust
Description: A view into contiguous `T`s, indexed by `I` rather than by `usize`.

Skip to main content

## IndexSlice

# Struct IndexSlice

Source

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

Expand description

A view into contiguous `T`s, 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 copy_within( &mut self, src: impl IntoSliceIdx<I, [T], Output: RangeBounds<usize>>, dest: I, )
where T: Copy,

Source

#### pub fn get<R: IntoSliceIdx<I, [T]>>( &self, index: R, ) -> Option<&<<R as IntoSliceIdx<I, [T]>>::Output as SliceIndex<[T]>>::Output>

Source

#### pub fn get_mut<R: IntoSliceIdx<I, [T]>>( &mut self, index: R, ) -> Option<&mut <<R as IntoSliceIdx<I, [T]>>::Output as SliceIndex<[T]>>::Output>

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` or if some of them are out of bounds.

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 or if some of them are out of bounds.

Source

#### pub fn binary_search(&self, value: &T) -> Result<I, I>
where T: Ord,

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()`.

## 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: Eq + Idx, T: Eq> Eq for IndexSlice<I, T>

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, R: IntoSliceIdx<I, [T]>> Index<R> for IndexSlice<I, T>

Source§

#### type Output = <<R as IntoSliceIdx<I, [T]>>::Output as SliceIndex<[T]>>::Output

The returned type after indexing.
Source§

#### fn index(&self, index: R) -> &Self::Output

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

### impl<I: Idx, T, R: IntoSliceIdx<I, [T]>> IndexMut<R> for IndexSlice<I, T>

Source§

#### fn index_mut(&mut self, index: R) -> &mut Self::Output

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 (const: unstable) · 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> Send for IndexSlice<I, T>
where T: Send,

Source§

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

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

## Auto Trait Implementations§

§

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

§

### 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> Sync for IndexSlice<I, T>
where T: Sync,

§

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

§

### impl<I, T> UnsafeUnpin for IndexSlice<I, T>
where T: UnsafeUnpin,

§

### 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.