Path: blob/main/crates/bevy_ecs/src/entity/unique_slice.rs
6849 views
//! A wrapper around entity slices with a uniqueness invariant.12use core::{3array::TryFromSliceError,4borrow::Borrow,5cmp::Ordering,6fmt::Debug,7iter::FusedIterator,8ops::{9Bound, Deref, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo,10RangeToInclusive,11},12ptr,13slice::{self, SliceIndex},14};1516use alloc::{17borrow::{Cow, ToOwned},18boxed::Box,19collections::VecDeque,20rc::Rc,21vec::Vec,22};2324use bevy_platform::sync::Arc;2526use super::{27unique_vec::{self, UniqueEntityEquivalentVec},28Entity, EntityEquivalent, EntitySet, EntitySetIterator, FromEntitySetIterator,29UniqueEntityEquivalentArray, UniqueEntityIter,30};3132/// A slice that contains only unique entities.33///34/// This can be obtained by slicing [`UniqueEntityEquivalentVec`].35///36/// When `T` is [`Entity`], use [`UniqueEntitySlice`].37#[repr(transparent)]38#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]39pub struct UniqueEntityEquivalentSlice<T: EntityEquivalent>([T]);4041/// A slice that contains only unique [`Entity`].42///43/// This is the default case of a [`UniqueEntityEquivalentSlice`].44pub type UniqueEntitySlice = UniqueEntityEquivalentSlice<Entity>;4546impl<T: EntityEquivalent> UniqueEntityEquivalentSlice<T> {47/// Constructs a `UniqueEntityEquivalentSlice` from a [`&[T]`] unsafely.48///49/// # Safety50///51/// `slice` must contain only unique elements.52pub const unsafe fn from_slice_unchecked(slice: &[T]) -> &Self {53// SAFETY: UniqueEntityEquivalentSlice is a transparent wrapper around [T].54unsafe { &*(ptr::from_ref(slice) as *const Self) }55}5657/// Constructs a `UniqueEntityEquivalentSlice` from a [`&mut [T]`] unsafely.58///59/// # Safety60///61/// `slice` must contain only unique elements.62pub const unsafe fn from_slice_unchecked_mut(slice: &mut [T]) -> &mut Self {63// SAFETY: UniqueEntityEquivalentSlice is a transparent wrapper around [T].64unsafe { &mut *(ptr::from_mut(slice) as *mut Self) }65}6667/// Casts to `self` to a standard slice.68pub const fn as_inner(&self) -> &[T] {69&self.070}7172/// Constructs a `UniqueEntityEquivalentSlice` from a [`Box<[T]>`] unsafely.73///74/// # Safety75///76/// `slice` must contain only unique elements.77pub unsafe fn from_boxed_slice_unchecked(slice: Box<[T]>) -> Box<Self> {78// SAFETY: UniqueEntityEquivalentSlice is a transparent wrapper around [T].79unsafe { Box::from_raw(Box::into_raw(slice) as *mut Self) }80}8182/// Casts `self` to the inner slice.83pub fn into_boxed_inner(self: Box<Self>) -> Box<[T]> {84// SAFETY: UniqueEntityEquivalentSlice is a transparent wrapper around [T].85unsafe { Box::from_raw(Box::into_raw(self) as *mut [T]) }86}8788/// Constructs a `UniqueEntityEquivalentSlice` from a [`Arc<[T]>`] unsafely.89///90/// # Safety91///92/// `slice` must contain only unique elements.93pub unsafe fn from_arc_slice_unchecked(slice: Arc<[T]>) -> Arc<Self> {94// SAFETY: UniqueEntityEquivalentSlice is a transparent wrapper around [T].95unsafe { Arc::from_raw(Arc::into_raw(slice) as *mut Self) }96}9798/// Casts `self` to the inner slice.99pub fn into_arc_inner(this: Arc<Self>) -> Arc<[T]> {100// SAFETY: UniqueEntityEquivalentSlice is a transparent wrapper around [T].101unsafe { Arc::from_raw(Arc::into_raw(this) as *mut [T]) }102}103104// Constructs a `UniqueEntityEquivalentSlice` from a [`Rc<[T]>`] unsafely.105///106/// # Safety107///108/// `slice` must contain only unique elements.109pub unsafe fn from_rc_slice_unchecked(slice: Rc<[T]>) -> Rc<Self> {110// SAFETY: UniqueEntityEquivalentSlice is a transparent wrapper around [T].111unsafe { Rc::from_raw(Rc::into_raw(slice) as *mut Self) }112}113114/// Casts `self` to the inner slice.115pub fn into_rc_inner(self: Rc<Self>) -> Rc<[T]> {116// SAFETY: UniqueEntityEquivalentSlice is a transparent wrapper around [T].117unsafe { Rc::from_raw(Rc::into_raw(self) as *mut [T]) }118}119120/// Returns the first and all the rest of the elements of the slice, or `None` if it is empty.121///122/// Equivalent to [`[T]::split_first`](slice::split_first).123pub const fn split_first(&self) -> Option<(&T, &Self)> {124let Some((first, rest)) = self.0.split_first() else {125return None;126};127// SAFETY: All elements in the original slice are unique.128Some((first, unsafe { Self::from_slice_unchecked(rest) }))129}130131/// Returns the last and all the rest of the elements of the slice, or `None` if it is empty.132///133/// Equivalent to [`[T]::split_last`](slice::split_last).134pub const fn split_last(&self) -> Option<(&T, &Self)> {135let Some((last, rest)) = self.0.split_last() else {136return None;137};138// SAFETY: All elements in the original slice are unique.139Some((last, unsafe { Self::from_slice_unchecked(rest) }))140}141142/// Returns an array reference to the first `N` items in the slice.143///144/// Equivalent to [`[T]::first_chunk`](slice::first_chunk).145pub const fn first_chunk<const N: usize>(&self) -> Option<&UniqueEntityEquivalentArray<T, N>> {146let Some(chunk) = self.0.first_chunk() else {147return None;148};149// SAFETY: All elements in the original slice are unique.150Some(unsafe { UniqueEntityEquivalentArray::from_array_ref_unchecked(chunk) })151}152153/// Returns an array reference to the first `N` items in the slice and the remaining slice.154///155/// Equivalent to [`[T]::split_first_chunk`](slice::split_first_chunk).156pub const fn split_first_chunk<const N: usize>(157&self,158) -> Option<(159&UniqueEntityEquivalentArray<T, N>,160&UniqueEntityEquivalentSlice<T>,161)> {162let Some((chunk, rest)) = self.0.split_first_chunk() else {163return None;164};165// SAFETY: All elements in the original slice are unique.166unsafe {167Some((168UniqueEntityEquivalentArray::from_array_ref_unchecked(chunk),169Self::from_slice_unchecked(rest),170))171}172}173174/// Returns an array reference to the last `N` items in the slice and the remaining slice.175///176/// Equivalent to [`[T]::split_last_chunk`](slice::split_last_chunk).177pub const fn split_last_chunk<const N: usize>(178&self,179) -> Option<(180&UniqueEntityEquivalentSlice<T>,181&UniqueEntityEquivalentArray<T, N>,182)> {183let Some((rest, chunk)) = self.0.split_last_chunk() else {184return None;185};186// SAFETY: All elements in the original slice are unique.187unsafe {188Some((189Self::from_slice_unchecked(rest),190UniqueEntityEquivalentArray::from_array_ref_unchecked(chunk),191))192}193}194195/// Returns an array reference to the last `N` items in the slice.196///197/// Equivalent to [`[T]::last_chunk`](slice::last_chunk).198pub const fn last_chunk<const N: usize>(&self) -> Option<&UniqueEntityEquivalentArray<T, N>> {199let Some(chunk) = self.0.last_chunk() else {200return None;201};202// SAFETY: All elements in the original slice are unique.203Some(unsafe { UniqueEntityEquivalentArray::from_array_ref_unchecked(chunk) })204}205206/// Returns a reference to a subslice.207///208/// Equivalent to the range functionality of [`[T]::get`].209///210/// Note that only the inner [`[T]::get`] supports indexing with a [`usize`].211///212/// [`[T]::get`]: `slice::get`213pub fn get<I>(&self, index: I) -> Option<&Self>214where215Self: Index<I>,216I: SliceIndex<[T], Output = [T]>,217{218self.0.get(index).map(|slice|219// SAFETY: All elements in the original slice are unique.220unsafe { Self::from_slice_unchecked(slice) })221}222223/// Returns a mutable reference to a subslice.224///225/// Equivalent to the range functionality of [`[T]::get_mut`].226///227/// Note that `UniqueEntityEquivalentSlice::get_mut` cannot be called with a [`usize`].228///229/// [`[T]::get_mut`]: `slice::get_mut`s230pub fn get_mut<I>(&mut self, index: I) -> Option<&mut Self>231where232Self: Index<I>,233I: SliceIndex<[T], Output = [T]>,234{235self.0.get_mut(index).map(|slice|236// SAFETY: All elements in the original slice are unique.237unsafe { Self::from_slice_unchecked_mut(slice) })238}239240/// Returns a reference to a subslice, without doing bounds checking.241///242/// Equivalent to the range functionality of [`[T]::get_unchecked`].243///244/// Note that only the inner [`[T]::get_unchecked`] supports indexing with a [`usize`].245///246/// # Safety247///248/// `index` must be safe to use with [`[T]::get_unchecked`]249///250/// [`[T]::get_unchecked`]: `slice::get_unchecked`251pub unsafe fn get_unchecked<I>(&self, index: I) -> &Self252where253Self: Index<I>,254I: SliceIndex<[T], Output = [T]>,255{256// SAFETY: All elements in the original slice are unique.257unsafe { Self::from_slice_unchecked(self.0.get_unchecked(index)) }258}259/// Returns a mutable reference to a subslice, without doing bounds checking.260///261/// Equivalent to the range functionality of [`[T]::get_unchecked_mut`].262///263/// Note that `UniqueEntityEquivalentSlice::get_unchecked_mut` cannot be called with an index.264///265/// # Safety266///267/// `index` must be safe to use with [`[T]::get_unchecked_mut`]268///269/// [`[T]::get_unchecked_mut`]: `slice::get_unchecked_mut`270pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut Self271where272Self: Index<I>,273I: SliceIndex<[T], Output = [T]>,274{275// SAFETY: All elements in the original slice are unique.276unsafe { Self::from_slice_unchecked_mut(self.0.get_unchecked_mut(index)) }277}278279/// Returns an unsafe mutable pointer to the slice's buffer.280pub const fn as_mut_ptr(&mut self) -> *mut T {281self.0.as_mut_ptr()282}283284/// Returns the two unsafe mutable pointers spanning the slice.285pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> {286self.0.as_mut_ptr_range()287}288289/// Swaps two elements in the slice.290pub fn swap(&mut self, a: usize, b: usize) {291self.0.swap(a, b);292}293294/// Reverses the order of elements in the slice, in place.295pub fn reverse(&mut self) {296self.0.reverse();297}298299/// Returns an iterator over the slice.300pub fn iter(&self) -> Iter<'_, T> {301// SAFETY: All elements in the original slice are unique.302unsafe { UniqueEntityIter::from_iterator_unchecked(self.0.iter()) }303}304305/// Returns an iterator over all contiguous windows of length306/// `size`.307///308/// Equivalent to [`[T]::windows`].309///310/// [`[T]::windows`]: `slice::windows`311pub fn windows(&self, size: usize) -> Windows<'_, T> {312// SAFETY: Any subslice of a unique slice is also unique.313unsafe {314UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.windows(size))315}316}317318/// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the319/// beginning of the slice.320///321/// Equivalent to [`[T]::chunks`].322///323/// [`[T]::chunks`]: `slice::chunks`324pub fn chunks(&self, chunk_size: usize) -> Chunks<'_, T> {325// SAFETY: Any subslice of a unique slice is also unique.326unsafe {327UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(328self.0.chunks(chunk_size),329)330}331}332333/// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the334/// beginning of the slice.335///336/// Equivalent to [`[T]::chunks_mut`].337///338/// [`[T]::chunks_mut`]: `slice::chunks_mut`339pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> {340// SAFETY: Any subslice of a unique slice is also unique.341unsafe {342UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(343self.0.chunks_mut(chunk_size),344)345}346}347348///349///350/// Equivalent to [`[T]::chunks_exact`].351///352/// [`[T]::chunks_exact`]: `slice::chunks_exact`353pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> {354// SAFETY: Any subslice of a unique slice is also unique.355unsafe {356UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(357self.0.chunks_exact(chunk_size),358)359}360}361362/// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the363/// beginning of the slice.364///365/// Equivalent to [`[T]::chunks_exact_mut`].366///367/// [`[T]::chunks_exact_mut`]: `slice::chunks_exact_mut`368pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> {369// SAFETY: Any subslice of a unique slice is also unique.370unsafe {371UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(372self.0.chunks_exact_mut(chunk_size),373)374}375}376377/// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end378/// of the slice.379///380/// Equivalent to [`[T]::rchunks`].381///382/// [`[T]::rchunks`]: `slice::rchunks`383pub fn rchunks(&self, chunk_size: usize) -> RChunks<'_, T> {384// SAFETY: Any subslice of a unique slice is also unique.385unsafe {386UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(387self.0.rchunks(chunk_size),388)389}390}391392/// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end393/// of the slice.394///395/// Equivalent to [`[T]::rchunks_mut`].396///397/// [`[T]::rchunks_mut`]: `slice::rchunks_mut`398pub fn rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, T> {399// SAFETY: Any subslice of a unique slice is also unique.400unsafe {401UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(402self.0.rchunks_mut(chunk_size),403)404}405}406407/// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the408/// end of the slice.409///410/// Equivalent to [`[T]::rchunks_exact`].411///412/// [`[T]::rchunks_exact`]: `slice::rchunks_exact`413pub fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> {414// SAFETY: Any subslice of a unique slice is also unique.415unsafe {416UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(417self.0.rchunks_exact(chunk_size),418)419}420}421422/// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end423/// of the slice.424///425/// Equivalent to [`[T]::rchunks_exact_mut`].426///427/// [`[T]::rchunks_exact_mut`]: `slice::rchunks_exact_mut`428pub fn rchunks_exact_mut(&mut self, chunk_size: usize) -> RChunksExactMut<'_, T> {429// SAFETY: Any subslice of a unique slice is also unique.430unsafe {431UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(432self.0.rchunks_exact_mut(chunk_size),433)434}435}436437/// Returns an iterator over the slice producing non-overlapping runs438/// of elements using the predicate to separate them.439///440/// Equivalent to [`[T]::chunk_by`].441///442/// [`[T]::chunk_by`]: `slice::chunk_by`443pub fn chunk_by<F>(&self, pred: F) -> ChunkBy<'_, F, T>444where445F: FnMut(&T, &T) -> bool,446{447// SAFETY: Any subslice of a unique slice is also unique.448unsafe {449UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.chunk_by(pred))450}451}452453/// Returns an iterator over the slice producing non-overlapping mutable454/// runs of elements using the predicate to separate them.455///456/// Equivalent to [`[T]::chunk_by_mut`].457///458/// [`[T]::chunk_by_mut`]: `slice::chunk_by_mut`459pub fn chunk_by_mut<F>(&mut self, pred: F) -> ChunkByMut<'_, F, T>460where461F: FnMut(&T, &T) -> bool,462{463// SAFETY: Any subslice of a unique slice is also unique.464unsafe {465UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(466self.0.chunk_by_mut(pred),467)468}469}470471/// Divides one slice into two at an index.472///473/// Equivalent to [`[T]::split_at`](slice::split_at).474pub const fn split_at(&self, mid: usize) -> (&Self, &Self) {475let (left, right) = self.0.split_at(mid);476// SAFETY: All elements in the original slice are unique.477unsafe {478(479Self::from_slice_unchecked(left),480Self::from_slice_unchecked(right),481)482}483}484485/// Divides one mutable slice into two at an index.486///487/// Equivalent to [`[T]::split_at_mut`](slice::split_at_mut).488pub const fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self) {489let (left, right) = self.0.split_at_mut(mid);490// SAFETY: All elements in the original slice are unique.491unsafe {492(493Self::from_slice_unchecked_mut(left),494Self::from_slice_unchecked_mut(right),495)496}497}498499/// Divides one slice into two at an index, without doing bounds checking.500///501/// Equivalent to [`[T]::split_at_unchecked`](slice::split_at_unchecked).502///503/// # Safety504///505/// `mid` must be safe to use in [`[T]::split_at_unchecked`].506///507/// [`[T]::split_at_unchecked`]: `slice::split_at_unchecked`508pub const unsafe fn split_at_unchecked(&self, mid: usize) -> (&Self, &Self) {509// SAFETY: The safety contract is upheld by the caller.510let (left, right) = unsafe { self.0.split_at_unchecked(mid) };511// SAFETY: All elements in the original slice are unique.512unsafe {513(514Self::from_slice_unchecked(left),515Self::from_slice_unchecked(right),516)517}518}519520/// Divides one mutable slice into two at an index, without doing bounds checking.521///522/// Equivalent to [`[T]::split_at_mut_unchecked`](slice::split_at_mut_unchecked).523///524/// # Safety525///526/// `mid` must be safe to use in [`[T]::split_at_mut_unchecked`].527///528/// [`[T]::split_at_mut_unchecked`]: `slice::split_at_mut_unchecked`529pub const unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut Self, &mut Self) {530// SAFETY: The safety contract is upheld by the caller.531let (left, right) = unsafe { self.0.split_at_mut_unchecked(mid) };532// SAFETY: All elements in the original slice are unique.533unsafe {534(535Self::from_slice_unchecked_mut(left),536Self::from_slice_unchecked_mut(right),537)538}539}540541/// Divides one slice into two at an index, returning `None` if the slice is542/// too short.543///544/// Equivalent to [`[T]::split_at_checked`](slice::split_at_checked).545pub const fn split_at_checked(&self, mid: usize) -> Option<(&Self, &Self)> {546let Some((left, right)) = self.0.split_at_checked(mid) else {547return None;548};549// SAFETY: All elements in the original slice are unique.550unsafe {551Some((552Self::from_slice_unchecked(left),553Self::from_slice_unchecked(right),554))555}556}557558/// Divides one mutable slice into two at an index, returning `None` if the559/// slice is too short.560///561/// Equivalent to [`[T]::split_at_mut_checked`](slice::split_at_mut_checked).562pub const fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&mut Self, &mut Self)> {563let Some((left, right)) = self.0.split_at_mut_checked(mid) else {564return None;565};566// SAFETY: All elements in the original slice are unique.567unsafe {568Some((569Self::from_slice_unchecked_mut(left),570Self::from_slice_unchecked_mut(right),571))572}573}574575/// Returns an iterator over subslices separated by elements that match576/// `pred`.577///578/// Equivalent to [`[T]::split`].579///580/// [`[T]::split`]: `slice::split`581pub fn split<F>(&self, pred: F) -> Split<'_, F, T>582where583F: FnMut(&T) -> bool,584{585// SAFETY: Any subslice of a unique slice is also unique.586unsafe {587UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.split(pred))588}589}590591/// Returns an iterator over mutable subslices separated by elements that592/// match `pred`.593///594/// Equivalent to [`[T]::split_mut`].595///596/// [`[T]::split_mut`]: `slice::split_mut`597pub fn split_mut<F>(&mut self, pred: F) -> SplitMut<'_, F, T>598where599F: FnMut(&T) -> bool,600{601// SAFETY: Any subslice of a unique slice is also unique.602unsafe {603UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(604self.0.split_mut(pred),605)606}607}608609/// Returns an iterator over subslices separated by elements that match610/// `pred`.611///612/// Equivalent to [`[T]::split_inclusive`].613///614/// [`[T]::split_inclusive`]: `slice::split_inclusive`615pub fn split_inclusive<F>(&self, pred: F) -> SplitInclusive<'_, F, T>616where617F: FnMut(&T) -> bool,618{619// SAFETY: Any subslice of a unique slice is also unique.620unsafe {621UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(622self.0.split_inclusive(pred),623)624}625}626627/// Returns an iterator over mutable subslices separated by elements that628/// match `pred`.629///630/// Equivalent to [`[T]::split_inclusive_mut`].631///632/// [`[T]::split_inclusive_mut`]: `slice::split_inclusive_mut`633pub fn split_inclusive_mut<F>(&mut self, pred: F) -> SplitInclusiveMut<'_, F, T>634where635F: FnMut(&T) -> bool,636{637// SAFETY: Any subslice of a unique slice is also unique.638unsafe {639UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(640self.0.split_inclusive_mut(pred),641)642}643}644645/// Returns an iterator over subslices separated by elements that match646/// `pred`, starting at the end of the slice and working backwards.647///648/// Equivalent to [`[T]::rsplit`].649///650/// [`[T]::rsplit`]: `slice::rsplit`651pub fn rsplit<F>(&self, pred: F) -> RSplit<'_, F, T>652where653F: FnMut(&T) -> bool,654{655// SAFETY: Any subslice of a unique slice is also unique.656unsafe {657UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.rsplit(pred))658}659}660661/// Returns an iterator over mutable subslices separated by elements that662/// match `pred`, starting at the end of the slice and working663/// backwards.664///665/// Equivalent to [`[T]::rsplit_mut`].666///667/// [`[T]::rsplit_mut`]: `slice::rsplit_mut`668pub fn rsplit_mut<F>(&mut self, pred: F) -> RSplitMut<'_, F, T>669where670F: FnMut(&T) -> bool,671{672// SAFETY: Any subslice of a unique slice is also unique.673unsafe {674UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(675self.0.rsplit_mut(pred),676)677}678}679680/// Returns an iterator over subslices separated by elements that match681/// `pred`, limited to returning at most `n` items.682///683/// Equivalent to [`[T]::splitn`].684///685/// [`[T]::splitn`]: `slice::splitn`686pub fn splitn<F>(&self, n: usize, pred: F) -> SplitN<'_, F, T>687where688F: FnMut(&T) -> bool,689{690// SAFETY: Any subslice of a unique slice is also unique.691unsafe {692UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.splitn(n, pred))693}694}695696/// Returns an iterator over mutable subslices separated by elements that match697/// `pred`, limited to returning at most `n` items.698///699/// Equivalent to [`[T]::splitn_mut`].700///701/// [`[T]::splitn_mut`]: `slice::splitn_mut`702pub fn splitn_mut<F>(&mut self, n: usize, pred: F) -> SplitNMut<'_, F, T>703where704F: FnMut(&T) -> bool,705{706// SAFETY: Any subslice of a unique slice is also unique.707unsafe {708UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(709self.0.splitn_mut(n, pred),710)711}712}713714/// Returns an iterator over subslices separated by elements that match715/// `pred` limited to returning at most `n` items.716///717/// Equivalent to [`[T]::rsplitn`].718///719/// [`[T]::rsplitn`]: `slice::rsplitn`720pub fn rsplitn<F>(&self, n: usize, pred: F) -> RSplitN<'_, F, T>721where722F: FnMut(&T) -> bool,723{724// SAFETY: Any subslice of a unique slice is also unique.725unsafe {726UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.rsplitn(n, pred))727}728}729730/// Returns an iterator over subslices separated by elements that match731/// `pred` limited to returning at most `n` items.732///733/// Equivalent to [`[T]::rsplitn_mut`].734///735/// [`[T]::rsplitn_mut`]: `slice::rsplitn_mut`736pub fn rsplitn_mut<F>(&mut self, n: usize, pred: F) -> RSplitNMut<'_, F, T>737where738F: FnMut(&T) -> bool,739{740// SAFETY: Any subslice of a unique slice is also unique.741unsafe {742UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(743self.0.rsplitn_mut(n, pred),744)745}746}747748/// Sorts the slice **without** preserving the initial order of equal elements.749///750/// Equivalent to [`[T]::sort_unstable`](slice::sort_unstable).751pub fn sort_unstable(&mut self)752where753T: Ord,754{755self.0.sort_unstable();756}757758/// Sorts the slice with a comparison function, **without** preserving the initial order of759/// equal elements.760///761/// Equivalent to [`[T]::sort_unstable_by`](slice::sort_unstable_by).762pub fn sort_unstable_by<F>(&mut self, compare: F)763where764F: FnMut(&T, &T) -> Ordering,765{766self.0.sort_unstable_by(compare);767}768769/// Sorts the slice with a key extraction function, **without** preserving the initial order of770/// equal elements.771///772/// Equivalent to [`[T]::sort_unstable_by_key`](slice::sort_unstable_by_key).773pub fn sort_unstable_by_key<K, F>(&mut self, f: F)774where775F: FnMut(&T) -> K,776K: Ord,777{778self.0.sort_unstable_by_key(f);779}780781/// Rotates the slice in-place such that the first `mid` elements of the782/// slice move to the end while the last `self.len() - mid` elements move to783/// the front.784///785/// Equivalent to [`[T]::rotate_left`](slice::rotate_left).786pub fn rotate_left(&mut self, mid: usize) {787self.0.rotate_left(mid);788}789790/// Rotates the slice in-place such that the first `self.len() - k`791/// elements of the slice move to the end while the last `k` elements move792/// to the front.793///794/// Equivalent to [`[T]::rotate_right`](slice::rotate_right).795pub fn rotate_right(&mut self, mid: usize) {796self.0.rotate_right(mid);797}798799/// Sorts the slice, preserving initial order of equal elements.800///801/// Equivalent to [`[T]::sort`](slice::sort()).802pub fn sort(&mut self)803where804T: Ord,805{806self.0.sort();807}808809/// Sorts the slice with a comparison function, preserving initial order of equal elements.810///811/// Equivalent to [`[T]::sort_by`](slice::sort_by).812pub fn sort_by<F>(&mut self, compare: F)813where814F: FnMut(&T, &T) -> Ordering,815{816self.0.sort_by(compare);817}818819/// Sorts the slice with a key extraction function, preserving initial order of equal elements.820///821/// Equivalent to [`[T]::sort_by_key`](slice::sort_by_key).822pub fn sort_by_key<K, F>(&mut self, f: F)823where824F: FnMut(&T) -> K,825K: Ord,826{827self.0.sort_by_key(f);828}829830// Sorts the slice with a key extraction function, preserving initial order of equal elements.831///832/// Equivalent to [`[T]::sort_by_cached_key`](slice::sort_by_cached_key).833pub fn sort_by_cached_key<K, F>(&mut self, f: F)834where835F: FnMut(&T) -> K,836K: Ord,837{838self.0.sort_by_cached_key(f);839}840841/// Copies self into a new `UniqueEntityEquivalentVec`.842pub fn to_vec(&self) -> UniqueEntityEquivalentVec<T>843where844T: Clone,845{846// SAFETY: All elements in the original slice are unique.847unsafe { UniqueEntityEquivalentVec::from_vec_unchecked(self.0.to_vec()) }848}849850/// Converts `self` into a vector without clones or allocation.851///852/// Equivalent to [`[T]::into_vec`](slice::into_vec).853pub fn into_vec(self: Box<Self>) -> UniqueEntityEquivalentVec<T> {854// SAFETY:855// This matches the implementation of `slice::into_vec`.856// All elements in the original slice are unique.857unsafe {858let len = self.len();859let vec = Vec::from_raw_parts(Box::into_raw(self).cast::<T>(), len, len);860UniqueEntityEquivalentVec::from_vec_unchecked(vec)861}862}863}864865/// Converts a reference to T into a slice of length 1 (without copying).866pub const fn from_ref<T: EntityEquivalent>(s: &T) -> &UniqueEntityEquivalentSlice<T> {867// SAFETY: A slice with a length of 1 is always unique.868unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(slice::from_ref(s)) }869}870871/// Converts a reference to T into a slice of length 1 (without copying).872pub const fn from_mut<T: EntityEquivalent>(s: &mut T) -> &mut UniqueEntityEquivalentSlice<T> {873// SAFETY: A slice with a length of 1 is always unique.874unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(slice::from_mut(s)) }875}876877/// Forms a slice from a pointer and a length.878///879/// Equivalent to [`slice::from_raw_parts`].880///881/// # Safety882///883/// [`slice::from_raw_parts`] must be safe to call with `data` and `len`.884/// Additionally, all elements in the resulting slice must be unique.885pub const unsafe fn from_raw_parts<'a, T: EntityEquivalent>(886data: *const T,887len: usize,888) -> &'a UniqueEntityEquivalentSlice<T> {889// SAFETY: The safety contract is upheld by the caller.890unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(slice::from_raw_parts(data, len)) }891}892893/// Performs the same functionality as [`from_raw_parts`], except that a mutable slice is returned.894///895/// Equivalent to [`slice::from_raw_parts_mut`].896///897/// # Safety898///899/// [`slice::from_raw_parts_mut`] must be safe to call with `data` and `len`.900/// Additionally, all elements in the resulting slice must be unique.901pub const unsafe fn from_raw_parts_mut<'a, T: EntityEquivalent>(902data: *mut T,903len: usize,904) -> &'a mut UniqueEntityEquivalentSlice<T> {905// SAFETY: The safety contract is upheld by the caller.906unsafe {907UniqueEntityEquivalentSlice::from_slice_unchecked_mut(slice::from_raw_parts_mut(data, len))908}909}910911/// Casts a slice of entity slices to a slice of [`UniqueEntityEquivalentSlice`]s.912///913/// # Safety914///915/// All elements in each of the cast slices must be unique.916pub unsafe fn cast_slice_of_unique_entity_slice<'a, 'b, T: EntityEquivalent + 'a>(917slice: &'b [&'a [T]],918) -> &'b [&'a UniqueEntityEquivalentSlice<T>] {919// SAFETY: All elements in the original iterator are unique slices.920unsafe { &*(ptr::from_ref(slice) as *const [&UniqueEntityEquivalentSlice<T>]) }921}922923/// Casts a mutable slice of entity slices to a slice of [`UniqueEntityEquivalentSlice`]s.924///925/// # Safety926///927/// All elements in each of the cast slices must be unique.928pub unsafe fn cast_slice_of_unique_entity_slice_mut<'a, 'b, T: EntityEquivalent + 'a>(929slice: &'b mut [&'a [T]],930) -> &'b mut [&'a UniqueEntityEquivalentSlice<T>] {931// SAFETY: All elements in the original iterator are unique slices.932unsafe { &mut *(ptr::from_mut(slice) as *mut [&UniqueEntityEquivalentSlice<T>]) }933}934935/// Casts a mutable slice of mutable entity slices to a slice of mutable [`UniqueEntityEquivalentSlice`]s.936///937/// # Safety938///939/// All elements in each of the cast slices must be unique.940pub unsafe fn cast_slice_of_mut_unique_entity_slice_mut<'a, 'b, T: EntityEquivalent + 'a>(941slice: &'b mut [&'a mut [T]],942) -> &'b mut [&'a mut UniqueEntityEquivalentSlice<T>] {943// SAFETY: All elements in the original iterator are unique slices.944unsafe { &mut *(ptr::from_mut(slice) as *mut [&mut UniqueEntityEquivalentSlice<T>]) }945}946947impl<'a, T: EntityEquivalent> IntoIterator for &'a UniqueEntityEquivalentSlice<T> {948type Item = &'a T;949950type IntoIter = Iter<'a, T>;951952fn into_iter(self) -> Self::IntoIter {953self.iter()954}955}956957impl<'a, T: EntityEquivalent> IntoIterator for &'a Box<UniqueEntityEquivalentSlice<T>> {958type Item = &'a T;959960type IntoIter = Iter<'a, T>;961962fn into_iter(self) -> Self::IntoIter {963self.iter()964}965}966967impl<T: EntityEquivalent> IntoIterator for Box<UniqueEntityEquivalentSlice<T>> {968type Item = T;969970type IntoIter = unique_vec::IntoIter<T>;971972fn into_iter(self) -> Self::IntoIter {973self.into_vec().into_iter()974}975}976977impl<T: EntityEquivalent> Deref for UniqueEntityEquivalentSlice<T> {978type Target = [T];979980fn deref(&self) -> &Self::Target {981&self.0982}983}984985impl<T: EntityEquivalent> AsRef<[T]> for UniqueEntityEquivalentSlice<T> {986fn as_ref(&self) -> &[T] {987self988}989}990991impl<T: EntityEquivalent> AsRef<Self> for UniqueEntityEquivalentSlice<T> {992fn as_ref(&self) -> &Self {993self994}995}996997impl<T: EntityEquivalent> AsMut<Self> for UniqueEntityEquivalentSlice<T> {998fn as_mut(&mut self) -> &mut Self {999self1000}1001}10021003impl<T: EntityEquivalent> Borrow<[T]> for UniqueEntityEquivalentSlice<T> {1004fn borrow(&self) -> &[T] {1005self1006}1007}10081009impl<T: EntityEquivalent + Clone> Clone for Box<UniqueEntityEquivalentSlice<T>> {1010fn clone(&self) -> Self {1011self.to_vec().into_boxed_slice()1012}1013}10141015impl<T: EntityEquivalent> Default for &UniqueEntityEquivalentSlice<T> {1016fn default() -> Self {1017// SAFETY: All elements in the original slice are unique.1018unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(Default::default()) }1019}1020}10211022impl<T: EntityEquivalent> Default for &mut UniqueEntityEquivalentSlice<T> {1023fn default() -> Self {1024// SAFETY: All elements in the original slice are unique.1025unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(Default::default()) }1026}1027}10281029impl<T: EntityEquivalent> Default for Box<UniqueEntityEquivalentSlice<T>> {1030fn default() -> Self {1031// SAFETY: All elements in the original slice are unique.1032unsafe { UniqueEntityEquivalentSlice::from_boxed_slice_unchecked(Default::default()) }1033}1034}10351036impl<T: EntityEquivalent + Clone> From<&UniqueEntityEquivalentSlice<T>>1037for Box<UniqueEntityEquivalentSlice<T>>1038{1039fn from(value: &UniqueEntityEquivalentSlice<T>) -> Self {1040// SAFETY: All elements in the original slice are unique.1041unsafe { UniqueEntityEquivalentSlice::from_boxed_slice_unchecked(value.0.into()) }1042}1043}10441045impl<T: EntityEquivalent + Clone> From<&UniqueEntityEquivalentSlice<T>>1046for Arc<UniqueEntityEquivalentSlice<T>>1047{1048fn from(value: &UniqueEntityEquivalentSlice<T>) -> Self {1049// SAFETY: All elements in the original slice are unique.1050unsafe { UniqueEntityEquivalentSlice::from_arc_slice_unchecked(value.0.into()) }1051}1052}10531054impl<T: EntityEquivalent + Clone> From<&UniqueEntityEquivalentSlice<T>>1055for Rc<UniqueEntityEquivalentSlice<T>>1056{1057fn from(value: &UniqueEntityEquivalentSlice<T>) -> Self {1058// SAFETY: All elements in the original slice are unique.1059unsafe { UniqueEntityEquivalentSlice::from_rc_slice_unchecked(value.0.into()) }1060}1061}10621063impl<'a, T: EntityEquivalent + Clone> From<&'a UniqueEntityEquivalentSlice<T>>1064for Cow<'a, UniqueEntityEquivalentSlice<T>>1065{1066fn from(value: &'a UniqueEntityEquivalentSlice<T>) -> Self {1067Cow::Borrowed(value)1068}1069}10701071impl<T: EntityEquivalent + Clone, const N: usize> From<UniqueEntityEquivalentArray<T, N>>1072for Box<UniqueEntityEquivalentSlice<T>>1073{1074fn from(value: UniqueEntityEquivalentArray<T, N>) -> Self {1075// SAFETY: All elements in the original slice are unique.1076unsafe {1077UniqueEntityEquivalentSlice::from_boxed_slice_unchecked(Box::new(value.into_inner()))1078}1079}1080}10811082impl<'a, T: EntityEquivalent + Clone> From<Cow<'a, UniqueEntityEquivalentSlice<T>>>1083for Box<UniqueEntityEquivalentSlice<T>>1084{1085fn from(value: Cow<'a, UniqueEntityEquivalentSlice<T>>) -> Self {1086match value {1087Cow::Borrowed(slice) => Box::from(slice),1088Cow::Owned(slice) => Box::from(slice),1089}1090}1091}10921093impl<T: EntityEquivalent> From<UniqueEntityEquivalentVec<T>>1094for Box<UniqueEntityEquivalentSlice<T>>1095{1096fn from(value: UniqueEntityEquivalentVec<T>) -> Self {1097value.into_boxed_slice()1098}1099}11001101impl<T: EntityEquivalent> FromIterator<T> for Box<UniqueEntityEquivalentSlice<T>> {1102fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {1103iter.into_iter()1104.collect::<UniqueEntityEquivalentVec<T>>()1105.into_boxed_slice()1106}1107}11081109impl<T: EntityEquivalent> FromEntitySetIterator<T> for Box<UniqueEntityEquivalentSlice<T>> {1110fn from_entity_set_iter<I: EntitySet<Item = T>>(iter: I) -> Self {1111iter.into_iter()1112.collect_set::<UniqueEntityEquivalentVec<T>>()1113.into_boxed_slice()1114}1115}11161117impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>1118PartialEq<UniqueEntityEquivalentVec<U>> for &UniqueEntityEquivalentSlice<T>1119{1120fn eq(&self, other: &UniqueEntityEquivalentVec<U>) -> bool {1121self.0.eq(other.as_vec())1122}1123}11241125impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>1126PartialEq<UniqueEntityEquivalentVec<U>> for &mut UniqueEntityEquivalentSlice<T>1127{1128fn eq(&self, other: &UniqueEntityEquivalentVec<U>) -> bool {1129self.0.eq(other.as_vec())1130}1131}11321133impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>1134PartialEq<UniqueEntityEquivalentVec<U>> for UniqueEntityEquivalentSlice<T>1135{1136fn eq(&self, other: &UniqueEntityEquivalentVec<U>) -> bool {1137self.0.eq(other.as_vec())1138}1139}11401141impl<T: PartialEq<U>, U: EntityEquivalent, const N: usize>1142PartialEq<&UniqueEntityEquivalentSlice<U>> for [T; N]1143{1144fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {1145self.eq(&other.0)1146}1147}11481149impl<T: PartialEq<U> + Clone, U: EntityEquivalent> PartialEq<&UniqueEntityEquivalentSlice<U>>1150for Cow<'_, [T]>1151{1152fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {1153self.eq(&&other.0)1154}1155}11561157impl<T: EntityEquivalent + PartialEq<U> + Clone, U: EntityEquivalent>1158PartialEq<&UniqueEntityEquivalentSlice<U>> for Cow<'_, UniqueEntityEquivalentSlice<T>>1159{1160fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {1161self.0.eq(&other.0)1162}1163}11641165impl<T: PartialEq<U>, U: EntityEquivalent> PartialEq<&UniqueEntityEquivalentSlice<U>> for Vec<T> {1166fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {1167self.eq(&other.0)1168}1169}11701171impl<T: PartialEq<U>, U: EntityEquivalent> PartialEq<&UniqueEntityEquivalentSlice<U>>1172for VecDeque<T>1173{1174fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {1175self.eq(&&other.0)1176}1177}11781179impl<T: PartialEq<U>, U: EntityEquivalent, const N: usize>1180PartialEq<&mut UniqueEntityEquivalentSlice<U>> for [T; N]1181{1182fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {1183self.eq(&other.0)1184}1185}11861187impl<T: PartialEq<U> + Clone, U: EntityEquivalent> PartialEq<&mut UniqueEntityEquivalentSlice<U>>1188for Cow<'_, [T]>1189{1190fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {1191self.eq(&&**other)1192}1193}11941195impl<T: EntityEquivalent + PartialEq<U> + Clone, U: EntityEquivalent>1196PartialEq<&mut UniqueEntityEquivalentSlice<U>> for Cow<'_, UniqueEntityEquivalentSlice<T>>1197{1198fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {1199self.0.eq(&other.0)1200}1201}12021203impl<T: EntityEquivalent + PartialEq<U> + Clone, U: EntityEquivalent>1204PartialEq<UniqueEntityEquivalentVec<U>> for Cow<'_, UniqueEntityEquivalentSlice<T>>1205{1206fn eq(&self, other: &UniqueEntityEquivalentVec<U>) -> bool {1207self.0.eq(other.as_vec())1208}1209}12101211impl<T: PartialEq<U>, U: EntityEquivalent> PartialEq<&mut UniqueEntityEquivalentSlice<U>>1212for Vec<T>1213{1214fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {1215self.eq(&other.0)1216}1217}12181219impl<T: PartialEq<U>, U: EntityEquivalent> PartialEq<&mut UniqueEntityEquivalentSlice<U>>1220for VecDeque<T>1221{1222fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {1223self.eq(&&other.0)1224}1225}12261227impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>1228PartialEq<UniqueEntityEquivalentSlice<U>> for [T]1229{1230fn eq(&self, other: &UniqueEntityEquivalentSlice<U>) -> bool {1231self.eq(&other.0)1232}1233}12341235impl<T: PartialEq<U>, U: EntityEquivalent, const N: usize> PartialEq<UniqueEntityEquivalentSlice<U>>1236for [T; N]1237{1238fn eq(&self, other: &UniqueEntityEquivalentSlice<U>) -> bool {1239self.eq(&other.0)1240}1241}12421243impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>1244PartialEq<UniqueEntityEquivalentSlice<U>> for Vec<T>1245{1246fn eq(&self, other: &UniqueEntityEquivalentSlice<U>) -> bool {1247self.eq(&other.0)1248}1249}12501251impl<T: EntityEquivalent + PartialEq<U>, U, const N: usize> PartialEq<[U; N]>1252for &UniqueEntityEquivalentSlice<T>1253{1254fn eq(&self, other: &[U; N]) -> bool {1255self.0.eq(other)1256}1257}12581259impl<T: EntityEquivalent + PartialEq<U>, U, const N: usize> PartialEq<[U; N]>1260for &mut UniqueEntityEquivalentSlice<T>1261{1262fn eq(&self, other: &[U; N]) -> bool {1263self.0.eq(other)1264}1265}12661267impl<T: EntityEquivalent + PartialEq<U>, U, const N: usize> PartialEq<[U; N]>1268for UniqueEntityEquivalentSlice<T>1269{1270fn eq(&self, other: &[U; N]) -> bool {1271self.0.eq(other)1272}1273}12741275impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent, const N: usize>1276PartialEq<UniqueEntityEquivalentArray<U, N>> for &UniqueEntityEquivalentSlice<T>1277{1278fn eq(&self, other: &UniqueEntityEquivalentArray<U, N>) -> bool {1279self.0.eq(&other.0)1280}1281}12821283impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent, const N: usize>1284PartialEq<UniqueEntityEquivalentArray<U, N>> for &mut UniqueEntityEquivalentSlice<T>1285{1286fn eq(&self, other: &UniqueEntityEquivalentArray<U, N>) -> bool {1287self.0.eq(&other.0)1288}1289}12901291impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent, const N: usize>1292PartialEq<UniqueEntityEquivalentArray<U, N>> for UniqueEntityEquivalentSlice<T>1293{1294fn eq(&self, other: &UniqueEntityEquivalentArray<U, N>) -> bool {1295self.0.eq(&other.0)1296}1297}12981299impl<T: EntityEquivalent + PartialEq<U>, U> PartialEq<Vec<U>> for &UniqueEntityEquivalentSlice<T> {1300fn eq(&self, other: &Vec<U>) -> bool {1301self.0.eq(other)1302}1303}13041305impl<T: EntityEquivalent + PartialEq<U>, U> PartialEq<Vec<U>>1306for &mut UniqueEntityEquivalentSlice<T>1307{1308fn eq(&self, other: &Vec<U>) -> bool {1309self.0.eq(other)1310}1311}13121313impl<T: EntityEquivalent + PartialEq<U>, U> PartialEq<Vec<U>> for UniqueEntityEquivalentSlice<T> {1314fn eq(&self, other: &Vec<U>) -> bool {1315self.0.eq(other)1316}1317}13181319impl<T: EntityEquivalent + Clone> ToOwned for UniqueEntityEquivalentSlice<T> {1320type Owned = UniqueEntityEquivalentVec<T>;13211322fn to_owned(&self) -> Self::Owned {1323// SAFETY: All elements in the original slice are unique.1324unsafe { UniqueEntityEquivalentVec::from_vec_unchecked(self.0.to_owned()) }1325}1326}13271328impl<'a, T: EntityEquivalent + Copy, const N: usize> TryFrom<&'a UniqueEntityEquivalentSlice<T>>1329for &'a UniqueEntityEquivalentArray<T, N>1330{1331type Error = TryFromSliceError;13321333fn try_from(value: &'a UniqueEntityEquivalentSlice<T>) -> Result<Self, Self::Error> {1334<&[T; N]>::try_from(&value.0).map(|array|1335// SAFETY: All elements in the original slice are unique.1336unsafe { UniqueEntityEquivalentArray::from_array_ref_unchecked(array) })1337}1338}13391340impl<T: EntityEquivalent + Copy, const N: usize> TryFrom<&UniqueEntityEquivalentSlice<T>>1341for UniqueEntityEquivalentArray<T, N>1342{1343type Error = TryFromSliceError;13441345fn try_from(value: &UniqueEntityEquivalentSlice<T>) -> Result<Self, Self::Error> {1346<&Self>::try_from(value).copied()1347}1348}13491350impl<T: EntityEquivalent + Copy, const N: usize> TryFrom<&mut UniqueEntityEquivalentSlice<T>>1351for UniqueEntityEquivalentArray<T, N>1352{1353type Error = TryFromSliceError;13541355fn try_from(value: &mut UniqueEntityEquivalentSlice<T>) -> Result<Self, Self::Error> {1356<Self>::try_from(&*value)1357}1358}13591360impl<T: EntityEquivalent> Index<(Bound<usize>, Bound<usize>)> for UniqueEntityEquivalentSlice<T> {1361type Output = Self;1362fn index(&self, key: (Bound<usize>, Bound<usize>)) -> &Self {1363// SAFETY: All elements in the original slice are unique.1364unsafe { Self::from_slice_unchecked(self.0.index(key)) }1365}1366}13671368impl<T: EntityEquivalent> Index<Range<usize>> for UniqueEntityEquivalentSlice<T> {1369type Output = Self;1370fn index(&self, key: Range<usize>) -> &Self {1371// SAFETY: All elements in the original slice are unique.1372unsafe { Self::from_slice_unchecked(self.0.index(key)) }1373}1374}13751376impl<T: EntityEquivalent> Index<RangeFrom<usize>> for UniqueEntityEquivalentSlice<T> {1377type Output = Self;1378fn index(&self, key: RangeFrom<usize>) -> &Self {1379// SAFETY: All elements in the original slice are unique.1380unsafe { Self::from_slice_unchecked(self.0.index(key)) }1381}1382}13831384impl<T: EntityEquivalent> Index<RangeFull> for UniqueEntityEquivalentSlice<T> {1385type Output = Self;1386fn index(&self, key: RangeFull) -> &Self {1387// SAFETY: All elements in the original slice are unique.1388unsafe { Self::from_slice_unchecked(self.0.index(key)) }1389}1390}13911392impl<T: EntityEquivalent> Index<RangeInclusive<usize>> for UniqueEntityEquivalentSlice<T> {1393type Output = UniqueEntityEquivalentSlice<T>;1394fn index(&self, key: RangeInclusive<usize>) -> &Self {1395// SAFETY: All elements in the original slice are unique.1396unsafe { Self::from_slice_unchecked(self.0.index(key)) }1397}1398}13991400impl<T: EntityEquivalent> Index<RangeTo<usize>> for UniqueEntityEquivalentSlice<T> {1401type Output = UniqueEntityEquivalentSlice<T>;1402fn index(&self, key: RangeTo<usize>) -> &Self {1403// SAFETY: All elements in the original slice are unique.1404unsafe { Self::from_slice_unchecked(self.0.index(key)) }1405}1406}14071408impl<T: EntityEquivalent> Index<RangeToInclusive<usize>> for UniqueEntityEquivalentSlice<T> {1409type Output = UniqueEntityEquivalentSlice<T>;1410fn index(&self, key: RangeToInclusive<usize>) -> &Self {1411// SAFETY: All elements in the original slice are unique.1412unsafe { Self::from_slice_unchecked(self.0.index(key)) }1413}1414}14151416impl<T: EntityEquivalent> Index<usize> for UniqueEntityEquivalentSlice<T> {1417type Output = T;14181419fn index(&self, index: usize) -> &T {1420&self.0[index]1421}1422}14231424impl<T: EntityEquivalent> IndexMut<(Bound<usize>, Bound<usize>)>1425for UniqueEntityEquivalentSlice<T>1426{1427fn index_mut(&mut self, key: (Bound<usize>, Bound<usize>)) -> &mut Self {1428// SAFETY: All elements in the original slice are unique.1429unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }1430}1431}14321433impl<T: EntityEquivalent> IndexMut<Range<usize>> for UniqueEntityEquivalentSlice<T> {1434fn index_mut(&mut self, key: Range<usize>) -> &mut Self {1435// SAFETY: All elements in the original slice are unique.1436unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }1437}1438}14391440impl<T: EntityEquivalent> IndexMut<RangeFrom<usize>> for UniqueEntityEquivalentSlice<T> {1441fn index_mut(&mut self, key: RangeFrom<usize>) -> &mut Self {1442// SAFETY: All elements in the original slice are unique.1443unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }1444}1445}14461447impl<T: EntityEquivalent> IndexMut<RangeFull> for UniqueEntityEquivalentSlice<T> {1448fn index_mut(&mut self, key: RangeFull) -> &mut Self {1449// SAFETY: All elements in the original slice are unique.1450unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }1451}1452}14531454impl<T: EntityEquivalent> IndexMut<RangeInclusive<usize>> for UniqueEntityEquivalentSlice<T> {1455fn index_mut(&mut self, key: RangeInclusive<usize>) -> &mut Self {1456// SAFETY: All elements in the original slice are unique.1457unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }1458}1459}14601461impl<T: EntityEquivalent> IndexMut<RangeTo<usize>> for UniqueEntityEquivalentSlice<T> {1462fn index_mut(&mut self, key: RangeTo<usize>) -> &mut Self {1463// SAFETY: All elements in the original slice are unique.1464unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }1465}1466}14671468impl<T: EntityEquivalent> IndexMut<RangeToInclusive<usize>> for UniqueEntityEquivalentSlice<T> {1469fn index_mut(&mut self, key: RangeToInclusive<usize>) -> &mut Self {1470// SAFETY: All elements in the original slice are unique.1471unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }1472}1473}14741475/// Immutable slice iterator.1476///1477/// This struct is created by [`iter`] method on [`UniqueEntityEquivalentSlice`] and1478/// the [`IntoIterator`] impls on it and [`UniqueEntityEquivalentVec`].1479///1480/// [`iter`]: `UniqueEntityEquivalentSlice::iter`1481pub type Iter<'a, T> = UniqueEntityIter<slice::Iter<'a, T>>;14821483impl<'a, T: EntityEquivalent> UniqueEntityIter<slice::Iter<'a, T>> {1484/// Views the underlying data as a subslice of the original data.1485///1486/// Equivalent to [`slice::Iter::as_slice`].1487pub fn as_slice(&self) -> &'a UniqueEntityEquivalentSlice<T> {1488// SAFETY: All elements in the original slice are unique.1489unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.as_inner().as_slice()) }1490}1491}14921493/// Mutable slice iterator.1494pub type IterMut<'a, T> = UniqueEntityIter<slice::IterMut<'a, T>>;14951496impl<'a, T: EntityEquivalent> UniqueEntityIter<slice::IterMut<'a, T>> {1497/// Views the underlying data as a mutable subslice of the original data.1498///1499/// Equivalent to [`slice::IterMut::into_slice`].1500pub fn into_slice(self) -> &'a mut UniqueEntityEquivalentSlice<T> {1501// SAFETY: All elements in the original slice are unique.1502unsafe {1503UniqueEntityEquivalentSlice::from_slice_unchecked_mut(self.into_inner().into_slice())1504}1505}15061507/// Views the underlying data as a subslice of the original data.1508///1509/// Equivalent to [`slice::IterMut::as_slice`].1510pub fn as_slice(&self) -> &UniqueEntityEquivalentSlice<T> {1511// SAFETY: All elements in the original slice are unique.1512unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.as_inner().as_slice()) }1513}1514}15151516/// An iterator that yields `&UniqueEntityEquivalentSlice`. Note that an entity may appear1517/// in multiple slices, depending on the wrapped iterator.1518#[derive(Debug)]1519pub struct UniqueEntityEquivalentSliceIter<1520'a,1521T: EntityEquivalent + 'a,1522I: Iterator<Item = &'a [T]>,1523> {1524pub(crate) iter: I,1525}15261527impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a [T]>>1528UniqueEntityEquivalentSliceIter<'a, T, I>1529{1530/// Constructs a [`UniqueEntityEquivalentSliceIter`] from a slice iterator unsafely.1531///1532/// # Safety1533///1534/// All elements in each of the slices must be unique.1535pub unsafe fn from_slice_iterator_unchecked(iter: I) -> Self {1536Self { iter }1537}15381539/// Returns the inner `I`.1540pub fn into_inner(self) -> I {1541self.iter1542}15431544/// Returns a reference to the inner `I`.1545pub fn as_inner(&self) -> &I {1546&self.iter1547}15481549/// Returns a mutable reference to the inner `I`.1550///1551/// # Safety1552///1553/// `self` must always contain an iterator that yields unique elements,1554/// even while this reference is live.1555pub unsafe fn as_mut_inner(&mut self) -> &mut I {1556&mut self.iter1557}1558}15591560impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a [T]>> Iterator1561for UniqueEntityEquivalentSliceIter<'a, T, I>1562{1563type Item = &'a UniqueEntityEquivalentSlice<T>;15641565fn next(&mut self) -> Option<Self::Item> {1566self.iter.next().map(|slice|1567// SAFETY: All elements in the original iterator are unique slices.1568unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(slice) })1569}15701571fn size_hint(&self) -> (usize, Option<usize>) {1572self.iter.size_hint()1573}1574}15751576impl<'a, T: EntityEquivalent + 'a, I: ExactSizeIterator<Item = &'a [T]>> ExactSizeIterator1577for UniqueEntityEquivalentSliceIter<'a, T, I>1578{1579}15801581impl<'a, T: EntityEquivalent + 'a, I: DoubleEndedIterator<Item = &'a [T]>> DoubleEndedIterator1582for UniqueEntityEquivalentSliceIter<'a, T, I>1583{1584fn next_back(&mut self) -> Option<Self::Item> {1585self.iter.next_back().map(|slice|1586// SAFETY: All elements in the original iterator are unique slices.1587unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(slice) })1588}1589}15901591impl<'a, T: EntityEquivalent + 'a, I: FusedIterator<Item = &'a [T]>> FusedIterator1592for UniqueEntityEquivalentSliceIter<'a, T, I>1593{1594}15951596impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a [T]> + AsRef<[&'a [T]]>>1597AsRef<[&'a UniqueEntityEquivalentSlice<T>]> for UniqueEntityEquivalentSliceIter<'a, T, I>1598{1599fn as_ref(&self) -> &[&'a UniqueEntityEquivalentSlice<T>] {1600// SAFETY:1601unsafe { cast_slice_of_unique_entity_slice(self.iter.as_ref()) }1602}1603}16041605/// An iterator over overlapping subslices of length `size`.1606///1607/// This struct is created by [`UniqueEntityEquivalentSlice::windows`].1608pub type Windows<'a, T = Entity> = UniqueEntityEquivalentSliceIter<'a, T, slice::Windows<'a, T>>;16091610/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a1611/// time), starting at the beginning of the slice.1612///1613/// This struct is created by [`UniqueEntityEquivalentSlice::chunks`].1614pub type Chunks<'a, T = Entity> = UniqueEntityEquivalentSliceIter<'a, T, slice::Chunks<'a, T>>;16151616/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a1617/// time), starting at the beginning of the slice.1618///1619/// This struct is created by [`UniqueEntityEquivalentSlice::chunks_exact`].1620pub type ChunksExact<'a, T = Entity> =1621UniqueEntityEquivalentSliceIter<'a, T, slice::ChunksExact<'a, T>>;16221623impl<'a, T: EntityEquivalent> UniqueEntityEquivalentSliceIter<'a, T, slice::ChunksExact<'a, T>> {1624/// Returns the remainder of the original slice that is not going to be1625/// returned by the iterator.1626///1627/// Equivalent to [`slice::ChunksExact::remainder`].1628pub fn remainder(&self) -> &'a UniqueEntityEquivalentSlice<T> {1629// SAFETY: All elements in the original iterator are unique slices.1630unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.iter.remainder()) }1631}1632}16331634/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a1635/// time), starting at the end of the slice.1636///1637/// This struct is created by [`UniqueEntityEquivalentSlice::rchunks`].1638pub type RChunks<'a, T = Entity> = UniqueEntityEquivalentSliceIter<'a, T, slice::RChunks<'a, T>>;16391640/// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a1641/// time), starting at the end of the slice.1642///1643/// This struct is created by [`UniqueEntityEquivalentSlice::rchunks_exact`].1644pub type RChunksExact<'a, T = Entity> =1645UniqueEntityEquivalentSliceIter<'a, T, slice::RChunksExact<'a, T>>;16461647impl<'a, T: EntityEquivalent> UniqueEntityEquivalentSliceIter<'a, T, slice::RChunksExact<'a, T>> {1648/// Returns the remainder of the original slice that is not going to be1649/// returned by the iterator.1650///1651/// Equivalent to [`slice::RChunksExact::remainder`].1652pub fn remainder(&self) -> &'a UniqueEntityEquivalentSlice<T> {1653// SAFETY: All elements in the original iterator are unique slices.1654unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.iter.remainder()) }1655}1656}16571658/// An iterator over slice in (non-overlapping) chunks separated by a predicate.1659///1660/// This struct is created by [`UniqueEntityEquivalentSlice::chunk_by`].1661pub type ChunkBy<'a, P, T = Entity> =1662UniqueEntityEquivalentSliceIter<'a, T, slice::ChunkBy<'a, T, P>>;16631664/// An iterator over subslices separated by elements that match a predicate1665/// function.1666///1667/// This struct is created by [`UniqueEntityEquivalentSlice::split`].1668pub type Split<'a, P, T = Entity> = UniqueEntityEquivalentSliceIter<'a, T, slice::Split<'a, T, P>>;16691670/// An iterator over subslices separated by elements that match a predicate1671/// function.1672///1673/// This struct is created by [`UniqueEntityEquivalentSlice::split_inclusive`].1674pub type SplitInclusive<'a, P, T = Entity> =1675UniqueEntityEquivalentSliceIter<'a, T, slice::SplitInclusive<'a, T, P>>;16761677/// An iterator over subslices separated by elements that match a predicate1678/// function, starting from the end of the slice.1679///1680/// This struct is created by [`UniqueEntityEquivalentSlice::rsplit`].1681pub type RSplit<'a, P, T = Entity> =1682UniqueEntityEquivalentSliceIter<'a, T, slice::RSplit<'a, T, P>>;16831684/// An iterator over subslices separated by elements that match a predicate1685/// function, limited to a given number of splits.1686///1687/// This struct is created by [`UniqueEntityEquivalentSlice::splitn`].1688pub type SplitN<'a, P, T = Entity> =1689UniqueEntityEquivalentSliceIter<'a, T, slice::SplitN<'a, T, P>>;16901691/// An iterator over subslices separated by elements that match a1692/// predicate function, limited to a given number of splits, starting1693/// from the end of the slice.1694///1695/// This struct is created by [`UniqueEntityEquivalentSlice::rsplitn`].1696pub type RSplitN<'a, P, T = Entity> =1697UniqueEntityEquivalentSliceIter<'a, T, slice::RSplitN<'a, T, P>>;16981699/// An iterator that yields `&mut UniqueEntityEquivalentSlice`. Note that an entity may appear1700/// in multiple slices, depending on the wrapped iterator.1701#[derive(Debug)]1702pub struct UniqueEntityEquivalentSliceIterMut<1703'a,1704T: EntityEquivalent + 'a,1705I: Iterator<Item = &'a mut [T]>,1706> {1707pub(crate) iter: I,1708}17091710impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a mut [T]>>1711UniqueEntityEquivalentSliceIterMut<'a, T, I>1712{1713/// Constructs a [`UniqueEntityEquivalentSliceIterMut`] from a mutable slice iterator unsafely.1714///1715/// # Safety1716///1717/// All elements in each of the slices must be unique.1718pub unsafe fn from_mut_slice_iterator_unchecked(iter: I) -> Self {1719Self { iter }1720}17211722/// Returns the inner `I`.1723pub fn into_inner(self) -> I {1724self.iter1725}17261727/// Returns a reference to the inner `I`.1728pub fn as_inner(&self) -> &I {1729&self.iter1730}17311732/// Returns a mutable reference to the inner `I`.1733///1734/// # Safety1735///1736/// `self` must always contain an iterator that yields unique elements,1737/// even while this reference is live.1738pub unsafe fn as_mut_inner(&mut self) -> &mut I {1739&mut self.iter1740}1741}17421743impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a mut [T]>> Iterator1744for UniqueEntityEquivalentSliceIterMut<'a, T, I>1745{1746type Item = &'a mut UniqueEntityEquivalentSlice<T>;17471748fn next(&mut self) -> Option<Self::Item> {1749self.iter.next().map(|slice|1750// SAFETY: All elements in the original iterator are unique slices.1751unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(slice) })1752}17531754fn size_hint(&self) -> (usize, Option<usize>) {1755self.iter.size_hint()1756}1757}17581759impl<'a, T: EntityEquivalent + 'a, I: ExactSizeIterator<Item = &'a mut [T]>> ExactSizeIterator1760for UniqueEntityEquivalentSliceIterMut<'a, T, I>1761{1762}17631764impl<'a, T: EntityEquivalent + 'a, I: DoubleEndedIterator<Item = &'a mut [T]>> DoubleEndedIterator1765for UniqueEntityEquivalentSliceIterMut<'a, T, I>1766{1767fn next_back(&mut self) -> Option<Self::Item> {1768self.iter.next_back().map(|slice|1769// SAFETY: All elements in the original iterator are unique slices.1770unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(slice) })1771}1772}17731774impl<'a, T: EntityEquivalent + 'a, I: FusedIterator<Item = &'a mut [T]>> FusedIterator1775for UniqueEntityEquivalentSliceIterMut<'a, T, I>1776{1777}17781779impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a mut [T]> + AsRef<[&'a [T]]>>1780AsRef<[&'a UniqueEntityEquivalentSlice<T>]> for UniqueEntityEquivalentSliceIterMut<'a, T, I>1781{1782fn as_ref(&self) -> &[&'a UniqueEntityEquivalentSlice<T>] {1783// SAFETY: All elements in the original iterator are unique slices.1784unsafe { cast_slice_of_unique_entity_slice(self.iter.as_ref()) }1785}1786}17871788impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a mut [T]> + AsMut<[&'a mut [T]]>>1789AsMut<[&'a mut UniqueEntityEquivalentSlice<T>]>1790for UniqueEntityEquivalentSliceIterMut<'a, T, I>1791{1792fn as_mut(&mut self) -> &mut [&'a mut UniqueEntityEquivalentSlice<T>] {1793// SAFETY: All elements in the original iterator are unique slices.1794unsafe { cast_slice_of_mut_unique_entity_slice_mut(self.iter.as_mut()) }1795}1796}17971798/// An iterator over a slice in (non-overlapping) mutable chunks (`chunk_size`1799/// elements at a time), starting at the beginning of the slice.1800///1801/// This struct is created by [`UniqueEntityEquivalentSlice::chunks_mut`].1802pub type ChunksMut<'a, T = Entity> =1803UniqueEntityEquivalentSliceIterMut<'a, T, slice::ChunksMut<'a, T>>;18041805/// An iterator over a slice in (non-overlapping) mutable chunks (`chunk_size`1806/// elements at a time), starting at the beginning of the slice.1807///1808/// This struct is created by [`UniqueEntityEquivalentSlice::chunks_exact_mut`].1809pub type ChunksExactMut<'a, T = Entity> =1810UniqueEntityEquivalentSliceIterMut<'a, T, slice::ChunksExactMut<'a, T>>;18111812impl<'a, T: EntityEquivalent>1813UniqueEntityEquivalentSliceIterMut<'a, T, slice::ChunksExactMut<'a, T>>1814{1815/// Returns the remainder of the original slice that is not going to be1816/// returned by the iterator.1817///1818/// Equivalent to [`slice::ChunksExactMut::into_remainder`].1819pub fn into_remainder(self) -> &'a mut UniqueEntityEquivalentSlice<T> {1820// SAFETY: All elements in the original iterator are unique slices.1821unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(self.iter.into_remainder()) }1822}1823}18241825/// An iterator over a slice in (non-overlapping) mutable chunks (`chunk_size`1826/// elements at a time), starting at the end of the slice.1827///1828/// This struct is created by [`UniqueEntityEquivalentSlice::rchunks_mut`].1829pub type RChunksMut<'a, T = Entity> =1830UniqueEntityEquivalentSliceIterMut<'a, T, slice::RChunksMut<'a, T>>;18311832/// An iterator over a slice in (non-overlapping) mutable chunks (`chunk_size`1833/// elements at a time), starting at the end of the slice.1834///1835/// This struct is created by [`UniqueEntityEquivalentSlice::rchunks_exact_mut`].1836pub type RChunksExactMut<'a, T = Entity> =1837UniqueEntityEquivalentSliceIterMut<'a, T, slice::RChunksExactMut<'a, T>>;18381839impl<'a, T: EntityEquivalent>1840UniqueEntityEquivalentSliceIterMut<'a, T, slice::RChunksExactMut<'a, T>>1841{1842/// Returns the remainder of the original slice that is not going to be1843/// returned by the iterator.1844///1845/// Equivalent to [`slice::RChunksExactMut::into_remainder`].1846pub fn into_remainder(self) -> &'a mut UniqueEntityEquivalentSlice<T> {1847// SAFETY: All elements in the original iterator are unique slices.1848unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(self.iter.into_remainder()) }1849}1850}18511852/// An iterator over slice in (non-overlapping) mutable chunks separated1853/// by a predicate.1854///1855/// This struct is created by [`UniqueEntityEquivalentSlice::chunk_by_mut`].1856pub type ChunkByMut<'a, P, T = Entity> =1857UniqueEntityEquivalentSliceIterMut<'a, T, slice::ChunkByMut<'a, T, P>>;18581859/// An iterator over the mutable subslices of the vector which are separated1860/// by elements that match `pred`.1861///1862/// This struct is created by [`UniqueEntityEquivalentSlice::split_mut`].1863pub type SplitMut<'a, P, T = Entity> =1864UniqueEntityEquivalentSliceIterMut<'a, T, slice::SplitMut<'a, T, P>>;18651866/// An iterator over the mutable subslices of the vector which are separated1867/// by elements that match `pred`. Unlike `SplitMut`, it contains the matched1868/// parts in the ends of the subslices.1869///1870/// This struct is created by [`UniqueEntityEquivalentSlice::split_inclusive_mut`].1871pub type SplitInclusiveMut<'a, P, T = Entity> =1872UniqueEntityEquivalentSliceIterMut<'a, T, slice::SplitInclusiveMut<'a, T, P>>;18731874/// An iterator over the subslices of the vector which are separated1875/// by elements that match `pred`, starting from the end of the slice.1876///1877/// This struct is created by [`UniqueEntityEquivalentSlice::rsplit_mut`].1878pub type RSplitMut<'a, P, T = Entity> =1879UniqueEntityEquivalentSliceIterMut<'a, T, slice::RSplitMut<'a, T, P>>;18801881/// An iterator over subslices separated by elements that match a predicate1882/// function, limited to a given number of splits.1883///1884/// This struct is created by [`UniqueEntityEquivalentSlice::splitn_mut`].1885pub type SplitNMut<'a, P, T = Entity> =1886UniqueEntityEquivalentSliceIterMut<'a, T, slice::SplitNMut<'a, T, P>>;18871888/// An iterator over subslices separated by elements that match a1889/// predicate function, limited to a given number of splits, starting1890/// from the end of the slice.1891///1892/// This struct is created by [`UniqueEntityEquivalentSlice::rsplitn_mut`].1893pub type RSplitNMut<'a, P, T = Entity> =1894UniqueEntityEquivalentSliceIterMut<'a, T, slice::RSplitNMut<'a, T, P>>;189518961897