Struct rustc_index::slice::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>
impl<I: Idx, T> IndexSlice<I, T>
pub const fn empty() -> &'static Self
pub const fn from_raw(raw: &[T]) -> &Self
pub fn from_raw_mut(raw: &mut [T]) -> &mut Self
pub const fn len(&self) -> usize
pub const fn is_empty(&self) -> bool
sourcepub fn next_index(&self) -> I
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()
).
pub fn iter(&self) -> Iter<'_, T>
pub fn iter_enumerated( &self ) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator + '_
pub fn indices( &self ) -> impl DoubleEndedIterator<Item = I> + ExactSizeIterator + Clone + 'static
pub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_enumerated_mut( &mut self ) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator + '_
pub fn last_index(&self) -> Option<I>
pub fn swap(&mut self, a: I, b: I)
pub fn get(&self, index: I) -> Option<&T>
pub fn get_mut(&mut self, index: I) -> Option<&mut T>
sourcepub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T)
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
.
sourcepub fn pick3_mut(&mut self, a: I, b: I, c: I) -> (&mut T, &mut T, &mut T)
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.
pub fn binary_search(&self, value: &T) -> Result<I, I>where
T: Ord,
source§impl<I: Idx, J: Idx> IndexSlice<I, J>
impl<I: Idx, J: Idx> IndexSlice<I, J>
sourcepub fn invert_bijective_mapping(&self) -> IndexVec<J, I>
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>
impl<I: Idx, T> Borrow<IndexSlice<I, T>> for IndexVec<I, T>
source§fn borrow(&self) -> &IndexSlice<I, T>
fn borrow(&self) -> &IndexSlice<I, T>
source§impl<I: Idx, T> BorrowMut<IndexSlice<I, T>> for IndexVec<I, T>
impl<I: Idx, T> BorrowMut<IndexSlice<I, T>> for IndexVec<I, T>
source§fn borrow_mut(&mut self) -> &mut IndexSlice<I, T>
fn borrow_mut(&mut self) -> &mut IndexSlice<I, T>
source§impl<I: Idx, T> Default for &IndexSlice<I, T>
impl<I: Idx, T> Default for &IndexSlice<I, T>
source§impl<I: Idx, T> Default for &mut IndexSlice<I, T>
impl<I: Idx, T> Default for &mut IndexSlice<I, T>
source§impl<I: Idx, T> Index<I> for IndexSlice<I, T>
impl<I: Idx, T> Index<I> for IndexSlice<I, T>
source§impl<I: Idx, T> IndexMut<I> for IndexSlice<I, T>
impl<I: Idx, T> IndexMut<I> for IndexSlice<I, T>
source§impl<'a, I: Idx, T> IntoIterator for &'a IndexSlice<I, T>
impl<'a, I: Idx, T> IntoIterator for &'a IndexSlice<I, T>
source§impl<'a, I: Idx, T> IntoIterator for &'a mut IndexSlice<I, T>
impl<'a, I: Idx, T> IntoIterator for &'a mut IndexSlice<I, T>
source§impl<I: PartialEq + Idx, T: PartialEq> PartialEq for IndexSlice<I, T>
impl<I: PartialEq + Idx, T: PartialEq> PartialEq for IndexSlice<I, T>
source§fn eq(&self, other: &IndexSlice<I, T>) -> bool
fn eq(&self, other: &IndexSlice<I, T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<I: Idx, T: Clone> ToOwned for IndexSlice<I, T>
impl<I: Idx, T: Clone> ToOwned for IndexSlice<I, T>
impl<I: Eq + Idx, T: Eq> Eq for IndexSlice<I, T>
impl<I: Idx, T> Send for IndexSlice<I, T>where
T: Send,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.