diff --git a/crates/bevy_ecs/src/entity/unique_array.rs b/crates/bevy_ecs/src/entity/unique_array.rs index 7bbf8e97df..a87e77676b 100644 --- a/crates/bevy_ecs/src/entity/unique_array.rs +++ b/crates/bevy_ecs/src/entity/unique_array.rs @@ -22,7 +22,7 @@ use bevy_platform_support::sync::Arc; use super::{ unique_slice::{self, UniqueEntitySlice}, - TrustedEntityBorrow, UniqueEntityIter, + Entity, TrustedEntityBorrow, UniqueEntityIter, }; /// An array that contains only unique entities. @@ -30,9 +30,9 @@ use super::{ /// It can be obtained through certain methods on [`UniqueEntitySlice`], /// and some [`TryFrom`] implementations. #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct UniqueEntityArray([T; N]); +pub struct UniqueEntityArray([T; N]); -impl UniqueEntityArray { +impl UniqueEntityArray { /// Constructs a `UniqueEntityArray` from a [`[T; N]`] unsafely. /// /// # Safety @@ -127,12 +127,12 @@ impl UniqueEntityArray { /// size as `self`. /// /// Equivalent to [`[T; N]::as_ref`](array::each_ref). - pub fn each_ref(&self) -> UniqueEntityArray<&T, N> { + pub fn each_ref(&self) -> UniqueEntityArray { UniqueEntityArray(self.0.each_ref()) } } -impl Deref for UniqueEntityArray { +impl Deref for UniqueEntityArray { type Target = UniqueEntitySlice; fn deref(&self) -> &Self::Target { @@ -141,19 +141,19 @@ impl Deref for UniqueEntityArray { } } -impl DerefMut for UniqueEntityArray { +impl DerefMut for UniqueEntityArray { fn deref_mut(&mut self) -> &mut Self::Target { // SAFETY: All elements in the original array are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(&mut self.0) } } } -impl Default for UniqueEntityArray { +impl Default for UniqueEntityArray<0, T> { fn default() -> Self { Self(Default::default()) } } -impl<'a, T: TrustedEntityBorrow, const N: usize> IntoIterator for &'a UniqueEntityArray { +impl<'a, T: TrustedEntityBorrow, const N: usize> IntoIterator for &'a UniqueEntityArray { type Item = &'a T; type IntoIter = unique_slice::Iter<'a, T>; @@ -164,10 +164,10 @@ impl<'a, T: TrustedEntityBorrow, const N: usize> IntoIterator for &'a UniqueEnti } } -impl IntoIterator for UniqueEntityArray { +impl IntoIterator for UniqueEntityArray { type Item = T; - type IntoIter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> Self::IntoIter { // SAFETY: All elements in the original array are unique. @@ -176,7 +176,7 @@ impl IntoIterator for UniqueEntityArray< } impl AsRef> - for UniqueEntityArray + for UniqueEntityArray { fn as_ref(&self) -> &UniqueEntitySlice { self @@ -184,7 +184,7 @@ impl AsRef> } impl AsMut> - for UniqueEntityArray + for UniqueEntityArray { fn as_mut(&mut self) -> &mut UniqueEntitySlice { self @@ -192,7 +192,7 @@ impl AsMut> } impl Borrow> - for UniqueEntityArray + for UniqueEntityArray { fn borrow(&self) -> &UniqueEntitySlice { self @@ -200,7 +200,7 @@ impl Borrow> } impl BorrowMut> - for UniqueEntityArray + for UniqueEntityArray { fn borrow_mut(&mut self) -> &mut UniqueEntitySlice { self @@ -208,7 +208,7 @@ impl BorrowMut> } impl Index<(Bound, Bound)> - for UniqueEntityArray + for UniqueEntityArray { type Output = UniqueEntitySlice; fn index(&self, key: (Bound, Bound)) -> &Self::Output { @@ -217,7 +217,7 @@ impl Index<(Bound, Bound)> } } -impl Index> for UniqueEntityArray { +impl Index> for UniqueEntityArray { type Output = UniqueEntitySlice; fn index(&self, key: Range) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -225,7 +225,7 @@ impl Index> for UniqueEntit } } -impl Index> for UniqueEntityArray { +impl Index> for UniqueEntityArray { type Output = UniqueEntitySlice; fn index(&self, key: RangeFrom) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -233,7 +233,7 @@ impl Index> for UniqueE } } -impl Index for UniqueEntityArray { +impl Index for UniqueEntityArray { type Output = UniqueEntitySlice; fn index(&self, key: RangeFull) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -242,7 +242,7 @@ impl Index for UniqueEntityAr } impl Index> - for UniqueEntityArray + for UniqueEntityArray { type Output = UniqueEntitySlice; fn index(&self, key: RangeInclusive) -> &Self::Output { @@ -251,7 +251,7 @@ impl Index> } } -impl Index> for UniqueEntityArray { +impl Index> for UniqueEntityArray { type Output = UniqueEntitySlice; fn index(&self, key: RangeTo) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -260,7 +260,7 @@ impl Index> for UniqueEnt } impl Index> - for UniqueEntityArray + for UniqueEntityArray { type Output = UniqueEntitySlice; fn index(&self, key: RangeToInclusive) -> &Self::Output { @@ -269,7 +269,7 @@ impl Index> } } -impl Index for UniqueEntityArray { +impl Index for UniqueEntityArray { type Output = T; fn index(&self, key: usize) -> &T { self.0.index(key) @@ -277,7 +277,7 @@ impl Index for UniqueEntityArray< } impl IndexMut<(Bound, Bound)> - for UniqueEntityArray + for UniqueEntityArray { fn index_mut(&mut self, key: (Bound, Bound)) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. @@ -285,7 +285,7 @@ impl IndexMut<(Bound, Bound IndexMut> for UniqueEntityArray { +impl IndexMut> for UniqueEntityArray { fn index_mut(&mut self, key: Range) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.0.index_mut(key)) } @@ -293,7 +293,7 @@ impl IndexMut> for UniqueEn } impl IndexMut> - for UniqueEntityArray + for UniqueEntityArray { fn index_mut(&mut self, key: RangeFrom) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. @@ -301,7 +301,7 @@ impl IndexMut> } } -impl IndexMut for UniqueEntityArray { +impl IndexMut for UniqueEntityArray { fn index_mut(&mut self, key: RangeFull) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.0.index_mut(key)) } @@ -309,7 +309,7 @@ impl IndexMut for UniqueEntit } impl IndexMut> - for UniqueEntityArray + for UniqueEntityArray { fn index_mut(&mut self, key: RangeInclusive) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. @@ -317,7 +317,7 @@ impl IndexMut> } } -impl IndexMut> for UniqueEntityArray { +impl IndexMut> for UniqueEntityArray { fn index_mut(&mut self, key: RangeTo) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.0.index_mut(key)) } @@ -325,7 +325,7 @@ impl IndexMut> for Unique } impl IndexMut> - for UniqueEntityArray + for UniqueEntityArray { fn index_mut(&mut self, key: RangeToInclusive) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. @@ -333,148 +333,148 @@ impl IndexMut> } } -impl From<&[T; 1]> for UniqueEntityArray { +impl From<&[T; 1]> for UniqueEntityArray<1, T> { fn from(value: &[T; 1]) -> Self { Self(value.clone()) } } -impl From<&[T; 0]> for UniqueEntityArray { +impl From<&[T; 0]> for UniqueEntityArray<0, T> { fn from(value: &[T; 0]) -> Self { Self(value.clone()) } } -impl From<&mut [T; 1]> for UniqueEntityArray { +impl From<&mut [T; 1]> for UniqueEntityArray<1, T> { fn from(value: &mut [T; 1]) -> Self { Self(value.clone()) } } -impl From<&mut [T; 0]> for UniqueEntityArray { +impl From<&mut [T; 0]> for UniqueEntityArray<0, T> { fn from(value: &mut [T; 0]) -> Self { Self(value.clone()) } } -impl From<[T; 1]> for UniqueEntityArray { +impl From<[T; 1]> for UniqueEntityArray<1, T> { fn from(value: [T; 1]) -> Self { Self(value) } } -impl From<[T; 0]> for UniqueEntityArray { +impl From<[T; 0]> for UniqueEntityArray<0, T> { fn from(value: [T; 0]) -> Self { Self(value) } } -impl From> for (T,) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T,) { + fn from(array: UniqueEntityArray<1, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T) { + fn from(array: UniqueEntityArray<2, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T) { + fn from(array: UniqueEntityArray<3, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T, T) { + fn from(array: UniqueEntityArray<4, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T, T, T) { + fn from(array: UniqueEntityArray<5, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T, T, T, T) { + fn from(array: UniqueEntityArray<6, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T, T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T, T, T, T, T) { + fn from(array: UniqueEntityArray<7, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T, T, T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T, T, T, T, T, T) { + fn from(array: UniqueEntityArray<8, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T, T, T, T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T, T, T, T, T, T, T) { + fn from(array: UniqueEntityArray<9, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T, T, T, T, T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T, T, T, T, T, T, T, T) { + fn from(array: UniqueEntityArray<10, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T, T, T, T, T, T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { +impl From> for (T, T, T, T, T, T, T, T, T, T, T) { + fn from(array: UniqueEntityArray<11, T>) -> Self { Self::from(array.into_inner()) } } -impl From> +impl From> for (T, T, T, T, T, T, T, T, T, T, T, T) { - fn from(array: UniqueEntityArray) -> Self { + fn from(array: UniqueEntityArray<12, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for BTreeSet { - fn from(value: UniqueEntityArray) -> Self { +impl From> for BTreeSet { + fn from(value: UniqueEntityArray) -> Self { BTreeSet::from(value.0) } } -impl From> for BinaryHeap { - fn from(value: UniqueEntityArray) -> Self { +impl From> for BinaryHeap { + fn from(value: UniqueEntityArray) -> Self { BinaryHeap::from(value.0) } } -impl From> for LinkedList { - fn from(value: UniqueEntityArray) -> Self { +impl From> for LinkedList { + fn from(value: UniqueEntityArray) -> Self { LinkedList::from(value.0) } } -impl From> for Vec { - fn from(value: UniqueEntityArray) -> Self { +impl From> for Vec { + fn from(value: UniqueEntityArray) -> Self { Vec::from(value.0) } } -impl From> for VecDeque { - fn from(value: UniqueEntityArray) -> Self { +impl From> for VecDeque { + fn from(value: UniqueEntityArray) -> Self { VecDeque::from(value.0) } } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq<&UniqueEntitySlice> for UniqueEntityArray + PartialEq<&UniqueEntitySlice> for UniqueEntityArray { fn eq(&self, other: &&UniqueEntitySlice) -> bool { self.0.eq(&other.as_inner()) @@ -482,47 +482,47 @@ impl, U: TrustedEntityBorrow, const N: usi } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq> for UniqueEntityArray + PartialEq> for UniqueEntityArray { fn eq(&self, other: &UniqueEntitySlice) -> bool { self.0.eq(other.as_inner()) } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueEntityArray> +impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueEntityArray> for Vec { - fn eq(&self, other: &&UniqueEntityArray) -> bool { + fn eq(&self, other: &&UniqueEntityArray) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueEntityArray> +impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueEntityArray> for VecDeque { - fn eq(&self, other: &&UniqueEntityArray) -> bool { + fn eq(&self, other: &&UniqueEntityArray) -> bool { self.eq(&other.0) } } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq<&mut UniqueEntityArray> for VecDeque + PartialEq<&mut UniqueEntityArray> for VecDeque { - fn eq(&self, other: &&mut UniqueEntityArray) -> bool { + fn eq(&self, other: &&mut UniqueEntityArray) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq> +impl, U: TrustedEntityBorrow, const N: usize> PartialEq> for Vec { - fn eq(&self, other: &UniqueEntityArray) -> bool { + fn eq(&self, other: &UniqueEntityArray) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq> +impl, U: TrustedEntityBorrow, const N: usize> PartialEq> for VecDeque { - fn eq(&self, other: &UniqueEntityArray) -> bool { + fn eq(&self, other: &UniqueEntityArray) -> bool { self.eq(&other.0) } } @@ -530,7 +530,7 @@ impl, U: TrustedEntityBorrow, const N: usize> PartialEq = UniqueEntityIter>; +pub type IntoIter = UniqueEntityIter>; impl UniqueEntityIter> { /// Returns an immutable slice of all elements that have not been yielded diff --git a/crates/bevy_ecs/src/entity/unique_slice.rs b/crates/bevy_ecs/src/entity/unique_slice.rs index a1db06b283..df2f1dc6d9 100644 --- a/crates/bevy_ecs/src/entity/unique_slice.rs +++ b/crates/bevy_ecs/src/entity/unique_slice.rs @@ -27,7 +27,8 @@ use bevy_platform_support::sync::Arc; use super::{ unique_array::UniqueEntityArray, unique_vec::{self, UniqueEntityVec}, - EntitySet, EntitySetIterator, FromEntitySetIterator, TrustedEntityBorrow, UniqueEntityIter, + Entity, EntitySet, EntitySetIterator, FromEntitySetIterator, TrustedEntityBorrow, + UniqueEntityIter, }; /// A slice that contains only unique entities. @@ -35,7 +36,7 @@ use super::{ /// It can be obtained by slicing [`UniqueEntityVec`]. #[repr(transparent)] #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct UniqueEntitySlice([T]); +pub struct UniqueEntitySlice([T]); impl UniqueEntitySlice { /// Constructs a `UniqueEntitySlice` from a [`&[T]`] unsafely. @@ -136,7 +137,7 @@ impl UniqueEntitySlice { /// Returns an array reference to the first `N` items in the slice. /// /// Equivalent to [`[T]::first_chunk`](slice::first_chunk). - pub const fn first_chunk(&self) -> Option<&UniqueEntityArray> { + pub const fn first_chunk(&self) -> Option<&UniqueEntityArray> { let Some(chunk) = self.0.first_chunk() else { return None; }; @@ -149,7 +150,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::split_first_chunk`](slice::split_first_chunk). pub const fn split_first_chunk( &self, - ) -> Option<(&UniqueEntityArray, &UniqueEntitySlice)> { + ) -> Option<(&UniqueEntityArray, &UniqueEntitySlice)> { let Some((chunk, rest)) = self.0.split_first_chunk() else { return None; }; @@ -167,7 +168,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::split_last_chunk`](slice::split_last_chunk). pub const fn split_last_chunk( &self, - ) -> Option<(&UniqueEntitySlice, &UniqueEntityArray)> { + ) -> Option<(&UniqueEntitySlice, &UniqueEntityArray)> { let Some((rest, chunk)) = self.0.split_last_chunk() else { return None; }; @@ -183,7 +184,7 @@ impl UniqueEntitySlice { /// Returns an array reference to the last `N` items in the slice. /// /// Equivalent to [`[T]::last_chunk`](slice::last_chunk). - pub const fn last_chunk(&self) -> Option<&UniqueEntityArray> { + pub const fn last_chunk(&self) -> Option<&UniqueEntityArray> { let Some(chunk) = self.0.last_chunk() else { return None; }; @@ -414,7 +415,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::chunk_by`]. /// /// [`[T]::chunk_by`]: `slice::chunk_by` - pub fn chunk_by(&self, pred: F) -> ChunkBy<'_, T, F> + pub fn chunk_by(&self, pred: F) -> ChunkBy<'_, F, T> where F: FnMut(&T, &T) -> bool, { @@ -428,7 +429,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::chunk_by_mut`]. /// /// [`[T]::chunk_by_mut`]: `slice::chunk_by_mut` - pub fn chunk_by_mut(&mut self, pred: F) -> ChunkByMut<'_, T, F> + pub fn chunk_by_mut(&mut self, pred: F) -> ChunkByMut<'_, F, T> where F: FnMut(&T, &T) -> bool, { @@ -548,7 +549,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::split`]. /// /// [`[T]::split`]: `slice::split` - pub fn split(&self, pred: F) -> Split<'_, T, F> + pub fn split(&self, pred: F) -> Split<'_, F, T> where F: FnMut(&T) -> bool, { @@ -562,7 +563,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::split_mut`]. /// /// [`[T]::split_mut`]: `slice::split_mut` - pub fn split_mut(&mut self, pred: F) -> SplitMut<'_, T, F> + pub fn split_mut(&mut self, pred: F) -> SplitMut<'_, F, T> where F: FnMut(&T) -> bool, { @@ -578,7 +579,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::split_inclusive`]. /// /// [`[T]::split_inclusive`]: `slice::split_inclusive` - pub fn split_inclusive(&self, pred: F) -> SplitInclusive<'_, T, F> + pub fn split_inclusive(&self, pred: F) -> SplitInclusive<'_, F, T> where F: FnMut(&T) -> bool, { @@ -594,7 +595,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::split_inclusive_mut`]. /// /// [`[T]::split_inclusive_mut`]: `slice::split_inclusive_mut` - pub fn split_inclusive_mut(&mut self, pred: F) -> SplitInclusiveMut<'_, T, F> + pub fn split_inclusive_mut(&mut self, pred: F) -> SplitInclusiveMut<'_, F, T> where F: FnMut(&T) -> bool, { @@ -612,7 +613,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::rsplit`]. /// /// [`[T]::rsplit`]: `slice::rsplit` - pub fn rsplit(&self, pred: F) -> RSplit<'_, T, F> + pub fn rsplit(&self, pred: F) -> RSplit<'_, F, T> where F: FnMut(&T) -> bool, { @@ -627,7 +628,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::rsplit_mut`]. /// /// [`[T]::rsplit_mut`]: `slice::rsplit_mut` - pub fn rsplit_mut(&mut self, pred: F) -> RSplitMut<'_, T, F> + pub fn rsplit_mut(&mut self, pred: F) -> RSplitMut<'_, F, T> where F: FnMut(&T) -> bool, { @@ -643,7 +644,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::splitn`]. /// /// [`[T]::splitn`]: `slice::splitn` - pub fn splitn(&self, n: usize, pred: F) -> SplitN<'_, T, F> + pub fn splitn(&self, n: usize, pred: F) -> SplitN<'_, F, T> where F: FnMut(&T) -> bool, { @@ -657,7 +658,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::splitn_mut`]. /// /// [`[T]::splitn_mut`]: `slice::splitn_mut` - pub fn splitn_mut(&mut self, n: usize, pred: F) -> SplitNMut<'_, T, F> + pub fn splitn_mut(&mut self, n: usize, pred: F) -> SplitNMut<'_, F, T> where F: FnMut(&T) -> bool, { @@ -673,7 +674,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::rsplitn`]. /// /// [`[T]::rsplitn`]: `slice::rsplitn` - pub fn rsplitn(&self, n: usize, pred: F) -> RSplitN<'_, T, F> + pub fn rsplitn(&self, n: usize, pred: F) -> RSplitN<'_, F, T> where F: FnMut(&T) -> bool, { @@ -687,7 +688,7 @@ impl UniqueEntitySlice { /// Equivalent to [`[T]::rsplitn_mut`]. /// /// [`[T]::rsplitn_mut`]: `slice::rsplitn_mut` - pub fn rsplitn_mut(&mut self, n: usize, pred: F) -> RSplitNMut<'_, T, F> + pub fn rsplitn_mut(&mut self, n: usize, pred: F) -> RSplitNMut<'_, F, T> where F: FnMut(&T) -> bool, { @@ -1012,10 +1013,10 @@ impl<'a, T: TrustedEntityBorrow + Clone> From<&'a UniqueEntitySlice> } } -impl From> +impl From> for Box> { - fn from(value: UniqueEntityArray) -> Self { + fn from(value: UniqueEntityArray) -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_boxed_slice_unchecked(Box::new(value.into_inner())) } } @@ -1207,25 +1208,25 @@ impl, U, const N: usize> PartialEq<[U; N]> } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq> for &UniqueEntitySlice + PartialEq> for &UniqueEntitySlice { - fn eq(&self, other: &UniqueEntityArray) -> bool { + fn eq(&self, other: &UniqueEntityArray) -> bool { self.0.eq(&other.0) } } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq> for &mut UniqueEntitySlice + PartialEq> for &mut UniqueEntitySlice { - fn eq(&self, other: &UniqueEntityArray) -> bool { + fn eq(&self, other: &UniqueEntityArray) -> bool { self.0.eq(&other.0) } } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq> for UniqueEntitySlice + PartialEq> for UniqueEntitySlice { - fn eq(&self, other: &UniqueEntityArray) -> bool { + fn eq(&self, other: &UniqueEntityArray) -> bool { self.0.eq(&other.0) } } @@ -1258,7 +1259,7 @@ impl ToOwned for UniqueEntitySlice { } impl<'a, T: TrustedEntityBorrow + Copy, const N: usize> TryFrom<&'a UniqueEntitySlice> - for &'a UniqueEntityArray + for &'a UniqueEntityArray { type Error = TryFromSliceError; @@ -1270,7 +1271,7 @@ impl<'a, T: TrustedEntityBorrow + Copy, const N: usize> TryFrom<&'a UniqueEntity } impl TryFrom<&UniqueEntitySlice> - for UniqueEntityArray + for UniqueEntityArray { type Error = TryFromSliceError; @@ -1280,7 +1281,7 @@ impl TryFrom<&UniqueEntitySlice TryFrom<&mut UniqueEntitySlice> - for UniqueEntityArray + for UniqueEntityArray { type Error = TryFromSliceError; @@ -1527,19 +1528,19 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator + AsRef<[&'a [ /// An iterator over overlapping subslices of length `size`. /// /// This struct is created by [`UniqueEntitySlice::windows`]. -pub type Windows<'a, T> = UniqueEntitySliceIter<'a, T, slice::Windows<'a, T>>; +pub type Windows<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::Windows<'a, T>>; /// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a /// time), starting at the beginning of the slice. /// /// This struct is created by [`UniqueEntitySlice::chunks`]. -pub type Chunks<'a, T> = UniqueEntitySliceIter<'a, T, slice::Chunks<'a, T>>; +pub type Chunks<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::Chunks<'a, T>>; /// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a /// time), starting at the beginning of the slice. /// /// This struct is created by [`UniqueEntitySlice::chunks_exact`]. -pub type ChunksExact<'a, T> = UniqueEntitySliceIter<'a, T, slice::ChunksExact<'a, T>>; +pub type ChunksExact<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::ChunksExact<'a, T>>; impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIter<'a, T, slice::ChunksExact<'a, T>> { /// Returns the remainder of the original slice that is not going to be @@ -1556,13 +1557,13 @@ impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIter<'a, T, slice::ChunksExact /// time), starting at the end of the slice. /// /// This struct is created by [`UniqueEntitySlice::rchunks`]. -pub type RChunks<'a, T> = UniqueEntitySliceIter<'a, T, slice::RChunks<'a, T>>; +pub type RChunks<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::RChunks<'a, T>>; /// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a /// time), starting at the end of the slice. /// /// This struct is created by [`UniqueEntitySlice::rchunks_exact`]. -pub type RChunksExact<'a, T> = UniqueEntitySliceIter<'a, T, slice::RChunksExact<'a, T>>; +pub type RChunksExact<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::RChunksExact<'a, T>>; impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIter<'a, T, slice::RChunksExact<'a, T>> { /// Returns the remainder of the original slice that is not going to be @@ -1578,38 +1579,39 @@ impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIter<'a, T, slice::RChunksExac /// An iterator over slice in (non-overlapping) chunks separated by a predicate. /// /// This struct is created by [`UniqueEntitySlice::chunk_by`]. -pub type ChunkBy<'a, T, P> = UniqueEntitySliceIter<'a, T, slice::ChunkBy<'a, T, P>>; +pub type ChunkBy<'a, P, T = Entity> = UniqueEntitySliceIter<'a, T, slice::ChunkBy<'a, T, P>>; /// An iterator over subslices separated by elements that match a predicate /// function. /// /// This struct is created by [`UniqueEntitySlice::split`]. -pub type Split<'a, T, P> = UniqueEntitySliceIter<'a, T, slice::Split<'a, T, P>>; +pub type Split<'a, P, T = Entity> = UniqueEntitySliceIter<'a, T, slice::Split<'a, T, P>>; /// An iterator over subslices separated by elements that match a predicate /// function. /// /// This struct is created by [`UniqueEntitySlice::split_inclusive`]. -pub type SplitInclusive<'a, T, P> = UniqueEntitySliceIter<'a, T, slice::SplitInclusive<'a, T, P>>; +pub type SplitInclusive<'a, P, T = Entity> = + UniqueEntitySliceIter<'a, T, slice::SplitInclusive<'a, T, P>>; /// An iterator over subslices separated by elements that match a predicate /// function, starting from the end of the slice. /// /// This struct is created by [`UniqueEntitySlice::rsplit`]. -pub type RSplit<'a, T, P> = UniqueEntitySliceIter<'a, T, slice::RSplit<'a, T, P>>; +pub type RSplit<'a, P, T = Entity> = UniqueEntitySliceIter<'a, T, slice::RSplit<'a, T, P>>; /// An iterator over subslices separated by elements that match a predicate /// function, limited to a given number of splits. /// /// This struct is created by [`UniqueEntitySlice::splitn`]. -pub type SplitN<'a, T, P> = UniqueEntitySliceIter<'a, T, slice::SplitN<'a, T, P>>; +pub type SplitN<'a, P, T = Entity> = UniqueEntitySliceIter<'a, T, slice::SplitN<'a, T, P>>; /// An iterator over subslices separated by elements that match a /// predicate function, limited to a given number of splits, starting /// from the end of the slice. /// /// This struct is created by [`UniqueEntitySlice::rsplitn`]. -pub type RSplitN<'a, T, P> = UniqueEntitySliceIter<'a, T, slice::RSplitN<'a, T, P>>; +pub type RSplitN<'a, P, T = Entity> = UniqueEntitySliceIter<'a, T, slice::RSplitN<'a, T, P>>; /// An iterator that yields `&mut UniqueEntitySlice`. Note that an entity may appear /// in multiple slices, depending on the wrapped iterator. @@ -1713,13 +1715,14 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator + AsMut<[& /// elements at a time), starting at the beginning of the slice. /// /// This struct is created by [`UniqueEntitySlice::chunks_mut`]. -pub type ChunksMut<'a, T> = UniqueEntitySliceIterMut<'a, T, slice::ChunksMut<'a, T>>; +pub type ChunksMut<'a, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::ChunksMut<'a, T>>; /// An iterator over a slice in (non-overlapping) mutable chunks (`chunk_size` /// elements at a time), starting at the beginning of the slice. /// /// This struct is created by [`UniqueEntitySlice::chunks_exact_mut`]. -pub type ChunksExactMut<'a, T> = UniqueEntitySliceIterMut<'a, T, slice::ChunksExactMut<'a, T>>; +pub type ChunksExactMut<'a, T = Entity> = + UniqueEntitySliceIterMut<'a, T, slice::ChunksExactMut<'a, T>>; impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIterMut<'a, T, slice::ChunksExactMut<'a, T>> { /// Returns the remainder of the original slice that is not going to be @@ -1736,13 +1739,14 @@ impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIterMut<'a, T, slice::ChunksEx /// elements at a time), starting at the end of the slice. /// /// This struct is created by [`UniqueEntitySlice::rchunks_mut`]. -pub type RChunksMut<'a, T> = UniqueEntitySliceIterMut<'a, T, slice::RChunksMut<'a, T>>; +pub type RChunksMut<'a, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::RChunksMut<'a, T>>; /// An iterator over a slice in (non-overlapping) mutable chunks (`chunk_size` /// elements at a time), starting at the end of the slice. /// /// This struct is created by [`UniqueEntitySlice::rchunks_exact_mut`]. -pub type RChunksExactMut<'a, T> = UniqueEntitySliceIterMut<'a, T, slice::RChunksExactMut<'a, T>>; +pub type RChunksExactMut<'a, T = Entity> = + UniqueEntitySliceIterMut<'a, T, slice::RChunksExactMut<'a, T>>; impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIterMut<'a, T, slice::RChunksExactMut<'a, T>> { /// Returns the remainder of the original slice that is not going to be @@ -1759,37 +1763,39 @@ impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIterMut<'a, T, slice::RChunksE /// by a predicate. /// /// This struct is created by [`UniqueEntitySlice::chunk_by_mut`]. -pub type ChunkByMut<'a, T, P> = UniqueEntitySliceIterMut<'a, T, slice::ChunkByMut<'a, T, P>>; +pub type ChunkByMut<'a, P, T = Entity> = + UniqueEntitySliceIterMut<'a, T, slice::ChunkByMut<'a, T, P>>; /// An iterator over the mutable subslices of the vector which are separated /// by elements that match `pred`. /// /// This struct is created by [`UniqueEntitySlice::split_mut`]. -pub type SplitMut<'a, T, P> = UniqueEntitySliceIterMut<'a, T, slice::SplitMut<'a, T, P>>; +pub type SplitMut<'a, P, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::SplitMut<'a, T, P>>; /// An iterator over the mutable subslices of the vector which are separated /// by elements that match `pred`. Unlike `SplitMut`, it contains the matched /// parts in the ends of the subslices. /// /// This struct is created by [`UniqueEntitySlice::split_inclusive_mut`]. -pub type SplitInclusiveMut<'a, T, P> = +pub type SplitInclusiveMut<'a, P, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::SplitInclusiveMut<'a, T, P>>; /// An iterator over the subslices of the vector which are separated /// by elements that match `pred`, starting from the end of the slice. /// /// This struct is created by [`UniqueEntitySlice::rsplit_mut`]. -pub type RSplitMut<'a, T, P> = UniqueEntitySliceIterMut<'a, T, slice::RSplitMut<'a, T, P>>; +pub type RSplitMut<'a, P, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::RSplitMut<'a, T, P>>; /// An iterator over subslices separated by elements that match a predicate /// function, limited to a given number of splits. /// /// This struct is created by [`UniqueEntitySlice::splitn_mut`]. -pub type SplitNMut<'a, T, P> = UniqueEntitySliceIterMut<'a, T, slice::SplitNMut<'a, T, P>>; +pub type SplitNMut<'a, P, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::SplitNMut<'a, T, P>>; /// An iterator over subslices separated by elements that match a /// predicate function, limited to a given number of splits, starting /// from the end of the slice. /// /// This struct is created by [`UniqueEntitySlice::rsplitn_mut`]. -pub type RSplitNMut<'a, T, P> = UniqueEntitySliceIterMut<'a, T, slice::RSplitNMut<'a, T, P>>; +pub type RSplitNMut<'a, P, T = Entity> = + UniqueEntitySliceIterMut<'a, T, slice::RSplitNMut<'a, T, P>>; diff --git a/crates/bevy_ecs/src/entity/unique_vec.rs b/crates/bevy_ecs/src/entity/unique_vec.rs index 38c484cae3..e22c4b0902 100644 --- a/crates/bevy_ecs/src/entity/unique_vec.rs +++ b/crates/bevy_ecs/src/entity/unique_vec.rs @@ -22,7 +22,7 @@ use bevy_platform_support::sync::Arc; use super::{ unique_array::UniqueEntityArray, unique_slice::{self, UniqueEntitySlice}, - EntitySet, FromEntitySetIterator, TrustedEntityBorrow, UniqueEntityIter, + Entity, EntitySet, FromEntitySetIterator, TrustedEntityBorrow, UniqueEntityIter, }; /// A `Vec` that contains only unique entities. @@ -36,7 +36,7 @@ use super::{ /// While this type can be constructed via `Iterator::collect`, doing so is inefficient, /// and not recommended. #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct UniqueEntityVec(Vec); +pub struct UniqueEntityVec(Vec); impl UniqueEntityVec { /// Constructs a new, empty `UniqueEntityVec`. @@ -555,9 +555,9 @@ impl, U, const N: usize> PartialEq<&[U; N] } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq<&UniqueEntityArray> for UniqueEntityVec + PartialEq<&UniqueEntityArray> for UniqueEntityVec { - fn eq(&self, other: &&UniqueEntityArray) -> bool { + fn eq(&self, other: &&UniqueEntityArray) -> bool { self.0.eq(&other.as_inner()) } } @@ -571,9 +571,9 @@ impl, U, const N: usize> PartialEq<&mut [U } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq<&mut UniqueEntityArray> for UniqueEntityVec + PartialEq<&mut UniqueEntityArray> for UniqueEntityVec { - fn eq(&self, other: &&mut UniqueEntityArray) -> bool { + fn eq(&self, other: &&mut UniqueEntityArray) -> bool { self.0.eq(other.as_inner()) } } @@ -601,9 +601,9 @@ impl, U, const N: usize> PartialEq<[U; N]> } impl, U: TrustedEntityBorrow, const N: usize> - PartialEq> for UniqueEntityVec + PartialEq> for UniqueEntityVec { - fn eq(&self, other: &UniqueEntityArray) -> bool { + fn eq(&self, other: &UniqueEntityArray) -> bool { self.0.eq(other.as_inner()) } } @@ -711,24 +711,24 @@ impl From<[T; 0]> for UniqueEntityVec { } } -impl From<&UniqueEntityArray> +impl From<&UniqueEntityArray> for UniqueEntityVec { - fn from(value: &UniqueEntityArray) -> Self { + fn from(value: &UniqueEntityArray) -> Self { Self(Vec::from(value.as_inner().clone())) } } -impl From<&mut UniqueEntityArray> +impl From<&mut UniqueEntityArray> for UniqueEntityVec { - fn from(value: &mut UniqueEntityArray) -> Self { + fn from(value: &mut UniqueEntityArray) -> Self { Self(Vec::from(value.as_inner().clone())) } } -impl From> for UniqueEntityVec { - fn from(value: UniqueEntityArray) -> Self { +impl From> for UniqueEntityVec { + fn from(value: UniqueEntityArray) -> Self { Self(Vec::from(value.into_inner())) } } @@ -806,7 +806,7 @@ impl TryFrom> for Box } impl TryFrom> - for Box> + for Box> { type Error = UniqueEntityVec; @@ -828,7 +828,7 @@ impl TryFrom> for [T; } impl TryFrom> - for UniqueEntityArray + for UniqueEntityArray { type Error = UniqueEntityVec; @@ -1043,7 +1043,7 @@ impl IndexMut> for UniqueEntityV /// /// This `struct` is created by the [`IntoIterator::into_iter`] trait /// method on [`UniqueEntityVec`]. -pub type IntoIter = UniqueEntityIter>; +pub type IntoIter = UniqueEntityIter>; impl UniqueEntityIter> { /// Returns the remaining items of this iterator as a slice. @@ -1067,7 +1067,7 @@ impl UniqueEntityIter> { /// /// This struct is created by [`UniqueEntityVec::drain`]. /// See its documentation for more. -pub type Drain<'a, T> = UniqueEntityIter>; +pub type Drain<'a, T = Entity> = UniqueEntityIter>; impl<'a, T: TrustedEntityBorrow> UniqueEntityIter> { /// Returns the remaining items of this iterator as a slice.