diff --git a/crates/bevy_ecs/src/entity/entity_set.rs b/crates/bevy_ecs/src/entity/entity_set.rs index 9e1a92d8f1..7608a7af5c 100644 --- a/crates/bevy_ecs/src/entity/entity_set.rs +++ b/crates/bevy_ecs/src/entity/entity_set.rs @@ -17,36 +17,57 @@ use super::{Entity, UniqueEntitySlice}; use bevy_platform_support::sync::Arc; -/// A trait for entity borrows. +/// A trait for types that contain an [`Entity`]. /// -/// This trait can be thought of as `Borrow`, but yielding `Entity` directly. -pub trait EntityBorrow { - /// Returns the borrowed entity. +/// This trait behaves similarly to `Borrow`, but yielding `Entity` directly. +/// +/// It should only be implemented when: +/// - Retrieving the [`Entity`] is a simple operation. +/// - The [`Entity`] contained by the type is unambiguous. +pub trait ContainsEntity { + /// Returns the contained entity. fn entity(&self) -> Entity; } -/// A trait for [`Entity`] borrows with trustworthy comparison behavior. +/// A trait for types that represent an [`Entity`]. /// -/// Comparison trait behavior between a [`TrustedEntityBorrow`] type and its underlying entity will match. +/// Comparison trait behavior between an [`EntityEquivalent`] type and its underlying entity will match. /// This property includes [`PartialEq`], [`Eq`], [`PartialOrd`], [`Ord`] and [`Hash`], /// and remains even after [`Clone`] and/or [`Borrow`] calls. /// /// # Safety -/// Any [`PartialEq`], [`Eq`], [`PartialOrd`], [`Ord`], and [`Hash`] impls must be -/// equivalent for `Self` and its underlying entity: -/// `x.entity() == y.entity()` should give the same result as `x == y`. -/// The above equivalence must also hold through and between calls to any [`Clone`] -/// and [`Borrow`]/[`BorrowMut`] impls in place of [`entity()`]. +/// Any [`PartialEq`], [`Eq`], [`PartialOrd`], and [`Ord`] impls must evaluate the same for `Self` and +/// its underlying entity. +/// `x.entity() == y.entity()` must be equivalent to `x == y`. +/// +/// The above equivalence must also hold through and between calls to any [`Clone`] and +/// [`Borrow`]/[`BorrowMut`] impls in place of [`entity()`]. /// /// The result of [`entity()`] must be unaffected by any interior mutability. /// +/// The aforementioned properties imply determinism in both [`entity()`] calls +/// and comparison trait behavior. +/// +/// All [`Hash`] impls except that for [`Entity`] must delegate to the [`Hash`] impl of +/// another [`EntityEquivalent`] type. All conversions to the delegatee within the [`Hash`] impl must +/// follow [`entity()`] equivalence. +/// +/// It should be noted that [`Hash`] is *not* a comparison trait, and with [`Hash::hash`] being forcibly +/// generic over all [`Hasher`]s, **cannot** guarantee determinism or uniqueness of any final hash values +/// on its own. +/// To obtain hash values forming the same total order as [`Entity`], any [`Hasher`] used must be +/// deterministic and concerning [`Entity`], collisionless. +/// Standard library hash collections handle collisions with an [`Eq`] fallback, but do not account for +/// determinism when [`BuildHasher`] is unspecified,. +/// /// [`Hash`]: core::hash::Hash +/// [`Hasher`]: core::hash::Hasher /// [`Borrow`]: core::borrow::Borrow /// [`BorrowMut`]: core::borrow::BorrowMut -/// [`entity()`]: EntityBorrow::entity -pub unsafe trait TrustedEntityBorrow: EntityBorrow + Eq {} +/// [`entity()`]: ContainsEntity::entity +pub unsafe trait EntityEquivalent: ContainsEntity + Eq {} -impl EntityBorrow for Entity { +impl ContainsEntity for Entity { fn entity(&self) -> Entity { *self } @@ -54,9 +75,9 @@ impl EntityBorrow for Entity { // SAFETY: // The trait implementations of Entity are correct and deterministic. -unsafe impl TrustedEntityBorrow for Entity {} +unsafe impl EntityEquivalent for Entity {} -impl EntityBorrow for &T { +impl ContainsEntity for &T { fn entity(&self) -> Entity { (**self).entity() } @@ -66,9 +87,9 @@ impl EntityBorrow for &T { // `&T` delegates `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` to T. // `Clone` and `Borrow` maintain equality. // `&T` is `Freeze`. -unsafe impl TrustedEntityBorrow for &T {} +unsafe impl EntityEquivalent for &T {} -impl EntityBorrow for &mut T { +impl ContainsEntity for &mut T { fn entity(&self) -> Entity { (**self).entity() } @@ -78,9 +99,9 @@ impl EntityBorrow for &mut T { // `&mut T` delegates `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` to T. // `Borrow` and `BorrowMut` maintain equality. // `&mut T` is `Freeze`. -unsafe impl TrustedEntityBorrow for &mut T {} +unsafe impl EntityEquivalent for &mut T {} -impl EntityBorrow for Box { +impl ContainsEntity for Box { fn entity(&self) -> Entity { (**self).entity() } @@ -90,9 +111,9 @@ impl EntityBorrow for Box { // `Box` delegates `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` to T. // `Clone`, `Borrow` and `BorrowMut` maintain equality. // `Box` is `Freeze`. -unsafe impl TrustedEntityBorrow for Box {} +unsafe impl EntityEquivalent for Box {} -impl EntityBorrow for Rc { +impl ContainsEntity for Rc { fn entity(&self) -> Entity { (**self).entity() } @@ -102,9 +123,9 @@ impl EntityBorrow for Rc { // `Rc` delegates `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` to T. // `Clone`, `Borrow` and `BorrowMut` maintain equality. // `Rc` is `Freeze`. -unsafe impl TrustedEntityBorrow for Rc {} +unsafe impl EntityEquivalent for Rc {} -impl EntityBorrow for Arc { +impl ContainsEntity for Arc { fn entity(&self) -> Entity { (**self).entity() } @@ -114,7 +135,7 @@ impl EntityBorrow for Arc { // `Arc` delegates `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` to T. // `Clone`, `Borrow` and `BorrowMut` maintain equality. // `Arc` is `Freeze`. -unsafe impl TrustedEntityBorrow for Arc {} +unsafe impl EntityEquivalent for Arc {} /// A set of unique entities. /// @@ -146,7 +167,7 @@ impl> EntitySet for T {} /// /// `x != y` must hold for any 2 elements returned by the iterator. /// This is always true for iterators that cannot return more than one element. -pub unsafe trait EntitySetIterator: Iterator { +pub unsafe trait EntitySetIterator: Iterator { /// Transforms an `EntitySetIterator` into a collection. /// /// This is a specialized form of [`collect`], for collections which benefit from the uniqueness guarantee. @@ -164,89 +185,86 @@ pub unsafe trait EntitySetIterator: Iterator { // SAFETY: // A correct `BTreeMap` contains only unique keys. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeMap`. -unsafe impl EntitySetIterator for btree_map::Keys<'_, K, V> {} +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeMap`. +unsafe impl EntitySetIterator for btree_map::Keys<'_, K, V> {} // SAFETY: // A correct `BTreeMap` contains only unique keys. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeMap`. -unsafe impl EntitySetIterator for btree_map::IntoKeys {} +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeMap`. +unsafe impl EntitySetIterator for btree_map::IntoKeys {} // SAFETY: // A correct `BTreeSet` contains only unique elements. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. // The sub-range maintains uniqueness. -unsafe impl EntitySetIterator for btree_set::Range<'_, T> {} +unsafe impl EntitySetIterator for btree_set::Range<'_, T> {} // SAFETY: // A correct `BTreeSet` contains only unique elements. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. // The "intersection" operation maintains uniqueness. -unsafe impl EntitySetIterator for btree_set::Intersection<'_, T> {} +unsafe impl EntitySetIterator for btree_set::Intersection<'_, T> {} // SAFETY: // A correct `BTreeSet` contains only unique elements. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. // The "union" operation maintains uniqueness. -unsafe impl EntitySetIterator for btree_set::Union<'_, T> {} +unsafe impl EntitySetIterator for btree_set::Union<'_, T> {} // SAFETY: // A correct `BTreeSet` contains only unique elements. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. // The "difference" operation maintains uniqueness. -unsafe impl EntitySetIterator for btree_set::Difference<'_, T> {} +unsafe impl EntitySetIterator for btree_set::Difference<'_, T> {} // SAFETY: // A correct `BTreeSet` contains only unique elements. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. // The "symmetric difference" operation maintains uniqueness. -unsafe impl EntitySetIterator - for btree_set::SymmetricDifference<'_, T> -{ -} +unsafe impl EntitySetIterator for btree_set::SymmetricDifference<'_, T> {} // SAFETY: // A correct `BTreeSet` contains only unique elements. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. -unsafe impl EntitySetIterator for btree_set::Iter<'_, T> {} +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. +unsafe impl EntitySetIterator for btree_set::Iter<'_, T> {} // SAFETY: // A correct `BTreeSet` contains only unique elements. -// TrustedEntityBorrow guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. -unsafe impl EntitySetIterator for btree_set::IntoIter {} +// EntityEquivalent guarantees a trustworthy Ord impl for T, and thus a correct `BTreeSet`. +unsafe impl EntitySetIterator for btree_set::IntoIter {} // SAFETY: This iterator only returns one element. -unsafe impl EntitySetIterator for option::Iter<'_, T> {} +unsafe impl EntitySetIterator for option::Iter<'_, T> {} // SAFETY: This iterator only returns one element. -// unsafe impl EntitySetIterator for option::IterMut<'_, T> {} +// unsafe impl EntitySetIterator for option::IterMut<'_, T> {} // SAFETY: This iterator only returns one element. -unsafe impl EntitySetIterator for option::IntoIter {} +unsafe impl EntitySetIterator for option::IntoIter {} // SAFETY: This iterator only returns one element. -unsafe impl EntitySetIterator for result::Iter<'_, T> {} +unsafe impl EntitySetIterator for result::Iter<'_, T> {} // SAFETY: This iterator only returns one element. -// unsafe impl EntitySetIterator for result::IterMut<'_, T> {} +// unsafe impl EntitySetIterator for result::IterMut<'_, T> {} // SAFETY: This iterator only returns one element. -unsafe impl EntitySetIterator for result::IntoIter {} +unsafe impl EntitySetIterator for result::IntoIter {} // SAFETY: This iterator only returns one element. -unsafe impl EntitySetIterator for array::IntoIter {} +unsafe impl EntitySetIterator for array::IntoIter {} // SAFETY: This iterator does not return any elements. -unsafe impl EntitySetIterator for array::IntoIter {} +unsafe impl EntitySetIterator for array::IntoIter {} // SAFETY: This iterator only returns one element. -unsafe impl T> EntitySetIterator for iter::OnceWith {} +unsafe impl T> EntitySetIterator for iter::OnceWith {} // SAFETY: This iterator only returns one element. -unsafe impl EntitySetIterator for iter::Once {} +unsafe impl EntitySetIterator for iter::Once {} // SAFETY: This iterator does not return any elements. -unsafe impl EntitySetIterator for iter::Empty {} +unsafe impl EntitySetIterator for iter::Empty {} // SAFETY: Taking a mutable reference of an iterator has no effect on its elements. unsafe impl EntitySetIterator for &mut I {} @@ -254,14 +272,14 @@ unsafe impl EntitySetIterator for &mut I {} // SAFETY: Boxing an iterator has no effect on its elements. unsafe impl EntitySetIterator for Box {} -// SAFETY: TrustedEntityBorrow ensures that Copy does not affect equality, via its restrictions on Clone. -unsafe impl<'a, T: 'a + TrustedEntityBorrow + Copy, I: EntitySetIterator> +// SAFETY: EntityEquivalent ensures that Copy does not affect equality, via its restrictions on Clone. +unsafe impl<'a, T: 'a + EntityEquivalent + Copy, I: EntitySetIterator> EntitySetIterator for iter::Copied { } -// SAFETY: TrustedEntityBorrow ensures that Clone does not affect equality. -unsafe impl<'a, T: 'a + TrustedEntityBorrow + Clone, I: EntitySetIterator> +// SAFETY: EntityEquivalent ensures that Clone does not affect equality. +unsafe impl<'a, T: 'a + EntityEquivalent + Clone, I: EntitySetIterator> EntitySetIterator for iter::Cloned { } @@ -277,7 +295,7 @@ unsafe impl EntitySetIterator for iter::Fuse {} // SAFETY: // Obtaining immutable references the elements of an iterator does not affect uniqueness. -// TrustedEntityBorrow ensures the lack of interior mutability. +// EntityEquivalent ensures the lack of interior mutability. unsafe impl::Item)> EntitySetIterator for iter::Inspect { @@ -316,12 +334,12 @@ unsafe impl EntitySetIterator for iter::StepBy {} /// /// See also: [`EntitySet`]. // FIXME: When subtrait item shadowing stabilizes, this should be renamed and shadow `FromIterator::from_iter` -pub trait FromEntitySetIterator: FromIterator { +pub trait FromEntitySetIterator: FromIterator { /// Creates a value from an [`EntitySetIterator`]. fn from_entity_set_iter>(set_iter: T) -> Self; } -impl FromEntitySetIterator +impl FromEntitySetIterator for HashSet { fn from_entity_set_iter>(set_iter: I) -> Self { @@ -340,7 +358,7 @@ impl FromEntitySetItera /// An iterator that yields unique entities. /// /// This wrapper can provide an [`EntitySetIterator`] implementation when an instance of `I` is known to uphold uniqueness. -pub struct UniqueEntityIter> { +pub struct UniqueEntityIter> { iter: I, } @@ -351,7 +369,7 @@ impl UniqueEntityIter { } } -impl> UniqueEntityIter { +impl> UniqueEntityIter { /// Constructs a [`UniqueEntityIter`] from an iterator unsafely. /// /// # Safety @@ -382,7 +400,7 @@ impl> UniqueEntityIter { } } -impl> Iterator for UniqueEntityIter { +impl> Iterator for UniqueEntityIter { type Item = I::Item; fn next(&mut self) -> Option { @@ -394,28 +412,26 @@ impl> Iterator for UniqueEntityIter { } } -impl> ExactSizeIterator for UniqueEntityIter {} +impl> ExactSizeIterator for UniqueEntityIter {} -impl> DoubleEndedIterator - for UniqueEntityIter -{ +impl> DoubleEndedIterator for UniqueEntityIter { fn next_back(&mut self) -> Option { self.iter.next_back() } } -impl> FusedIterator for UniqueEntityIter {} +impl> FusedIterator for UniqueEntityIter {} // SAFETY: The underlying iterator is ensured to only return unique elements by its construction. -unsafe impl> EntitySetIterator for UniqueEntityIter {} +unsafe impl> EntitySetIterator for UniqueEntityIter {} -impl + AsRef<[T]>> AsRef<[T]> for UniqueEntityIter { +impl + AsRef<[T]>> AsRef<[T]> for UniqueEntityIter { fn as_ref(&self) -> &[T] { self.iter.as_ref() } } -impl + AsRef<[T]>> +impl + AsRef<[T]>> AsRef> for UniqueEntityIter { fn as_ref(&self) -> &UniqueEntitySlice { @@ -424,7 +440,7 @@ impl + AsRef<[T]> } } -impl + AsMut<[T]>> +impl + AsMut<[T]>> AsMut> for UniqueEntityIter { fn as_mut(&mut self) -> &mut UniqueEntitySlice { @@ -451,7 +467,7 @@ impl Clone for UniqueEntityIter { } } -impl + Debug> Debug for UniqueEntityIter { +impl + Debug> Debug for UniqueEntityIter { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { f.debug_struct("UniqueEntityIter") .field("iter", &self.iter) diff --git a/crates/bevy_ecs/src/entity/hash_map.rs b/crates/bevy_ecs/src/entity/hash_map.rs index 39fbfb1d87..d10be929f8 100644 --- a/crates/bevy_ecs/src/entity/hash_map.rs +++ b/crates/bevy_ecs/src/entity/hash_map.rs @@ -13,7 +13,7 @@ use bevy_platform_support::collections::hash_map::{self, HashMap}; #[cfg(feature = "bevy_reflect")] use bevy_reflect::Reflect; -use super::{Entity, EntityHash, EntitySetIterator, TrustedEntityBorrow}; +use super::{Entity, EntityEquivalent, EntityHash, EntitySetIterator}; /// A [`HashMap`] pre-configured to use [`EntityHash`] hashing. #[cfg_attr(feature = "bevy_reflect", derive(Reflect))] @@ -113,7 +113,7 @@ impl FromIterator<(Entity, V)> for EntityHashMap { } } -impl Index<&Q> for EntityHashMap { +impl Index<&Q> for EntityHashMap { type Output = V; fn index(&self, key: &Q) -> &V { self.0.index(&key.entity()) diff --git a/crates/bevy_ecs/src/entity/index_map.rs b/crates/bevy_ecs/src/entity/index_map.rs index de174ae3c8..6f3c2d76df 100644 --- a/crates/bevy_ecs/src/entity/index_map.rs +++ b/crates/bevy_ecs/src/entity/index_map.rs @@ -19,7 +19,7 @@ use core::{ use bevy_reflect::Reflect; use indexmap::map::{self, IndexMap, IntoValues, ValuesMut}; -use super::{Entity, EntityHash, EntitySetIterator, TrustedEntityBorrow}; +use super::{Entity, EntityEquivalent, EntityHash, EntitySetIterator}; use bevy_platform_support::prelude::Box; @@ -176,7 +176,7 @@ impl FromIterator<(Entity, V)> for EntityIndexMap { } } -impl Index<&Q> for EntityIndexMap { +impl Index<&Q> for EntityIndexMap { type Output = V; fn index(&self, key: &Q) -> &V { self.0.index(&key.entity()) @@ -246,7 +246,7 @@ impl Index for EntityIndexMap { } } -impl IndexMut<&Q> for EntityIndexMap { +impl IndexMut<&Q> for EntityIndexMap { fn index_mut(&mut self, key: &Q) -> &mut V { self.0.index_mut(&key.entity()) } diff --git a/crates/bevy_ecs/src/entity/unique_array.rs b/crates/bevy_ecs/src/entity/unique_array.rs index a87e77676b..7cfee9cb4d 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}, - Entity, TrustedEntityBorrow, UniqueEntityIter, + Entity, EntityEquivalent, 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 @@ -132,7 +132,7 @@ impl UniqueEntityArray { } } -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<0, T> { +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: EntityEquivalent, const N: usize> IntoIterator for &'a UniqueEntityArray { type Item = &'a T; type IntoIter = unique_slice::Iter<'a, T>; @@ -164,7 +164,7 @@ 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; @@ -175,31 +175,25 @@ impl IntoIterator for UniqueEntityArray< } } -impl AsRef> - for UniqueEntityArray -{ +impl AsRef> for UniqueEntityArray { fn as_ref(&self) -> &UniqueEntitySlice { self } } -impl AsMut> - for UniqueEntityArray -{ +impl AsMut> for UniqueEntityArray { fn as_mut(&mut self) -> &mut UniqueEntitySlice { self } } -impl Borrow> - for UniqueEntityArray -{ +impl Borrow> for UniqueEntityArray { fn borrow(&self) -> &UniqueEntitySlice { self } } -impl BorrowMut> +impl BorrowMut> for UniqueEntityArray { fn borrow_mut(&mut self) -> &mut UniqueEntitySlice { @@ -207,7 +201,7 @@ impl BorrowMut> } } -impl Index<(Bound, Bound)> +impl Index<(Bound, Bound)> for UniqueEntityArray { type Output = UniqueEntitySlice; @@ -217,7 +211,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 +219,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 +227,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. @@ -241,9 +235,7 @@ impl Index for UniqueEntityAr } } -impl Index> - for UniqueEntityArray -{ +impl Index> for UniqueEntityArray { type Output = UniqueEntitySlice; fn index(&self, key: RangeInclusive) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -251,7 +243,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. @@ -259,7 +251,7 @@ impl Index> for UniqueEnt } } -impl Index> +impl Index> for UniqueEntityArray { type Output = UniqueEntitySlice; @@ -269,14 +261,14 @@ impl Index> } } -impl Index for UniqueEntityArray { +impl Index for UniqueEntityArray { type Output = T; fn index(&self, key: usize) -> &T { self.0.index(key) } } -impl IndexMut<(Bound, Bound)> +impl IndexMut<(Bound, Bound)> for UniqueEntityArray { fn index_mut(&mut self, key: (Bound, Bound)) -> &mut Self::Output { @@ -285,30 +277,28 @@ 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)) } } } -impl IndexMut> - for UniqueEntityArray -{ +impl IndexMut> for UniqueEntityArray { fn index_mut(&mut self, key: RangeFrom) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -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)) } } } -impl IndexMut> +impl IndexMut> for UniqueEntityArray { fn index_mut(&mut self, key: RangeInclusive) -> &mut Self::Output { @@ -317,14 +307,14 @@ 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)) } } } -impl IndexMut> +impl IndexMut> for UniqueEntityArray { fn index_mut(&mut self, key: RangeToInclusive) -> &mut Self::Output { @@ -333,147 +323,145 @@ impl IndexMut> } } -impl From<&[T; 1]> for UniqueEntityArray<1, T> { +impl From<&[T; 1]> for UniqueEntityArray<1, T> { fn from(value: &[T; 1]) -> Self { Self(value.clone()) } } -impl From<&[T; 0]> for UniqueEntityArray<0, T> { +impl From<&[T; 0]> for UniqueEntityArray<0, T> { fn from(value: &[T; 0]) -> Self { Self(value.clone()) } } -impl From<&mut [T; 1]> for UniqueEntityArray<1, T> { +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<0, T> { +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<1, T> { +impl From<[T; 1]> for UniqueEntityArray<1, T> { fn from(value: [T; 1]) -> Self { Self(value) } } -impl From<[T; 0]> for UniqueEntityArray<0, T> { +impl From<[T; 0]> for UniqueEntityArray<0, T> { fn from(value: [T; 0]) -> Self { Self(value) } } -impl From> for (T,) { +impl From> for (T,) { fn from(array: UniqueEntityArray<1, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T) { +impl From> for (T, T) { fn from(array: UniqueEntityArray<2, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for (T, T, T) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +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> - for (T, T, T, T, T, T, T, T, T, T, T, T) -{ +impl From> for (T, T, T, T, T, T, T, T, T, T, T, T) { fn from(array: UniqueEntityArray<12, T>) -> Self { Self::from(array.into_inner()) } } -impl From> for BTreeSet { +impl From> for BTreeSet { fn from(value: UniqueEntityArray) -> Self { BTreeSet::from(value.0) } } -impl From> for BinaryHeap { +impl From> for BinaryHeap { fn from(value: UniqueEntityArray) -> Self { BinaryHeap::from(value.0) } } -impl From> for LinkedList { +impl From> for LinkedList { fn from(value: UniqueEntityArray) -> Self { LinkedList::from(value.0) } } -impl From> for Vec { +impl From> for Vec { fn from(value: UniqueEntityArray) -> Self { Vec::from(value.0) } } -impl From> for VecDeque { +impl From> for VecDeque { fn from(value: UniqueEntityArray) -> Self { VecDeque::from(value.0) } } -impl, U: TrustedEntityBorrow, const N: usize> +impl, U: EntityEquivalent, const N: usize> PartialEq<&UniqueEntitySlice> for UniqueEntityArray { fn eq(&self, other: &&UniqueEntitySlice) -> bool { @@ -481,7 +469,7 @@ impl, U: TrustedEntityBorrow, const N: usi } } -impl, U: TrustedEntityBorrow, const N: usize> +impl, U: EntityEquivalent, const N: usize> PartialEq> for UniqueEntityArray { fn eq(&self, other: &UniqueEntitySlice) -> bool { @@ -489,14 +477,14 @@ impl, U: TrustedEntityBorrow, const N: usi } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueEntityArray> +impl, U: EntityEquivalent, const N: usize> PartialEq<&UniqueEntityArray> for Vec { fn eq(&self, other: &&UniqueEntityArray) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueEntityArray> +impl, U: EntityEquivalent, const N: usize> PartialEq<&UniqueEntityArray> for VecDeque { fn eq(&self, other: &&UniqueEntityArray) -> bool { @@ -504,22 +492,22 @@ impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueE } } -impl, U: TrustedEntityBorrow, const N: usize> - PartialEq<&mut UniqueEntityArray> for VecDeque +impl, U: EntityEquivalent, const N: usize> PartialEq<&mut UniqueEntityArray> + for VecDeque { fn eq(&self, other: &&mut UniqueEntityArray) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq> +impl, U: EntityEquivalent, const N: usize> PartialEq> for Vec { fn eq(&self, other: &UniqueEntityArray) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq> +impl, U: EntityEquivalent, const N: usize> PartialEq> for VecDeque { fn eq(&self, other: &UniqueEntityArray) -> bool { @@ -532,7 +520,7 @@ impl, U: TrustedEntityBorrow, const N: usize> PartialEq = UniqueEntityIter>; -impl UniqueEntityIter> { +impl UniqueEntityIter> { /// Returns an immutable slice of all elements that have not been yielded /// yet. /// diff --git a/crates/bevy_ecs/src/entity/unique_slice.rs b/crates/bevy_ecs/src/entity/unique_slice.rs index 9ce9179a3d..d4a7186a7c 100644 --- a/crates/bevy_ecs/src/entity/unique_slice.rs +++ b/crates/bevy_ecs/src/entity/unique_slice.rs @@ -26,7 +26,7 @@ use bevy_platform_support::sync::Arc; use super::{ unique_vec::{self, UniqueEntityVec}, - Entity, EntitySet, EntitySetIterator, FromEntitySetIterator, TrustedEntityBorrow, + Entity, EntityEquivalent, EntitySet, EntitySetIterator, FromEntitySetIterator, UniqueEntityArray, UniqueEntityIter, }; @@ -35,9 +35,9 @@ 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 { +impl UniqueEntitySlice { /// Constructs a `UniqueEntitySlice` from a [`&[T]`] unsafely. /// /// # Safety @@ -815,13 +815,13 @@ impl UniqueEntitySlice { } /// Converts a reference to T into a slice of length 1 (without copying). -pub const fn from_ref(s: &T) -> &UniqueEntitySlice { +pub const fn from_ref(s: &T) -> &UniqueEntitySlice { // SAFETY: A slice with a length of 1 is always unique. unsafe { UniqueEntitySlice::from_slice_unchecked(slice::from_ref(s)) } } /// Converts a reference to T into a slice of length 1 (without copying). -pub const fn from_mut(s: &mut T) -> &mut UniqueEntitySlice { +pub const fn from_mut(s: &mut T) -> &mut UniqueEntitySlice { // SAFETY: A slice with a length of 1 is always unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(slice::from_mut(s)) } } @@ -834,7 +834,7 @@ pub const fn from_mut(s: &mut T) -> &mut UniqueEntitySli /// /// [`slice::from_raw_parts`] must be safe to call with `data` and `len`. /// Additionally, all elements in the resulting slice must be unique. -pub const unsafe fn from_raw_parts<'a, T: TrustedEntityBorrow>( +pub const unsafe fn from_raw_parts<'a, T: EntityEquivalent>( data: *const T, len: usize, ) -> &'a UniqueEntitySlice { @@ -850,7 +850,7 @@ pub const unsafe fn from_raw_parts<'a, T: TrustedEntityBorrow>( /// /// [`slice::from_raw_parts_mut`] must be safe to call with `data` and `len`. /// Additionally, all elements in the resulting slice must be unique. -pub const unsafe fn from_raw_parts_mut<'a, T: TrustedEntityBorrow>( +pub const unsafe fn from_raw_parts_mut<'a, T: EntityEquivalent>( data: *mut T, len: usize, ) -> &'a mut UniqueEntitySlice { @@ -863,7 +863,7 @@ pub const unsafe fn from_raw_parts_mut<'a, T: TrustedEntityBorrow>( /// # Safety /// /// All elements in each of the casted slices must be unique. -pub unsafe fn cast_slice_of_unique_entity_slice<'a, 'b, T: TrustedEntityBorrow + 'a>( +pub unsafe fn cast_slice_of_unique_entity_slice<'a, 'b, T: EntityEquivalent + 'a>( slice: &'b [&'a [T]], ) -> &'b [&'a UniqueEntitySlice] { // SAFETY: All elements in the original iterator are unique slices. @@ -875,7 +875,7 @@ pub unsafe fn cast_slice_of_unique_entity_slice<'a, 'b, T: TrustedEntityBorrow + /// # Safety /// /// All elements in each of the casted slices must be unique. -pub unsafe fn cast_slice_of_unique_entity_slice_mut<'a, 'b, T: TrustedEntityBorrow + 'a>( +pub unsafe fn cast_slice_of_unique_entity_slice_mut<'a, 'b, T: EntityEquivalent + 'a>( slice: &'b mut [&'a [T]], ) -> &'b mut [&'a UniqueEntitySlice] { // SAFETY: All elements in the original iterator are unique slices. @@ -887,14 +887,14 @@ pub unsafe fn cast_slice_of_unique_entity_slice_mut<'a, 'b, T: TrustedEntityBorr /// # Safety /// /// All elements in each of the casted slices must be unique. -pub unsafe fn cast_slice_of_mut_unique_entity_slice_mut<'a, 'b, T: TrustedEntityBorrow + 'a>( +pub unsafe fn cast_slice_of_mut_unique_entity_slice_mut<'a, 'b, T: EntityEquivalent + 'a>( slice: &'b mut [&'a mut [T]], ) -> &'b mut [&'a mut UniqueEntitySlice] { // SAFETY: All elements in the original iterator are unique slices. unsafe { &mut *(ptr::from_mut(slice) as *mut [&mut UniqueEntitySlice]) } } -impl<'a, T: TrustedEntityBorrow> IntoIterator for &'a UniqueEntitySlice { +impl<'a, T: EntityEquivalent> IntoIterator for &'a UniqueEntitySlice { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -904,7 +904,7 @@ impl<'a, T: TrustedEntityBorrow> IntoIterator for &'a UniqueEntitySlice { } } -impl<'a, T: TrustedEntityBorrow> IntoIterator for &'a Box> { +impl<'a, T: EntityEquivalent> IntoIterator for &'a Box> { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -914,7 +914,7 @@ impl<'a, T: TrustedEntityBorrow> IntoIterator for &'a Box> } } -impl IntoIterator for Box> { +impl IntoIterator for Box> { type Item = T; type IntoIter = unique_vec::IntoIter; @@ -924,7 +924,7 @@ impl IntoIterator for Box> { } } -impl Deref for UniqueEntitySlice { +impl Deref for UniqueEntitySlice { type Target = [T]; fn deref(&self) -> &Self::Target { @@ -932,79 +932,79 @@ impl Deref for UniqueEntitySlice { } } -impl AsRef<[T]> for UniqueEntitySlice { +impl AsRef<[T]> for UniqueEntitySlice { fn as_ref(&self) -> &[T] { self } } -impl AsRef for UniqueEntitySlice { +impl AsRef for UniqueEntitySlice { fn as_ref(&self) -> &Self { self } } -impl AsMut for UniqueEntitySlice { +impl AsMut for UniqueEntitySlice { fn as_mut(&mut self) -> &mut Self { self } } -impl Borrow<[T]> for UniqueEntitySlice { +impl Borrow<[T]> for UniqueEntitySlice { fn borrow(&self) -> &[T] { self } } -impl Clone for Box> { +impl Clone for Box> { fn clone(&self) -> Self { self.to_vec().into_boxed_slice() } } -impl Default for &UniqueEntitySlice { +impl Default for &UniqueEntitySlice { fn default() -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked(Default::default()) } } } -impl Default for &mut UniqueEntitySlice { +impl Default for &mut UniqueEntitySlice { fn default() -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(Default::default()) } } } -impl Default for Box> { +impl Default for Box> { fn default() -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_boxed_slice_unchecked(Default::default()) } } } -impl From<&UniqueEntitySlice> for Box> { +impl From<&UniqueEntitySlice> for Box> { fn from(value: &UniqueEntitySlice) -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_boxed_slice_unchecked(value.0.into()) } } } -impl From<&UniqueEntitySlice> for Arc> { +impl From<&UniqueEntitySlice> for Arc> { fn from(value: &UniqueEntitySlice) -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_arc_slice_unchecked(value.0.into()) } } } -impl From<&UniqueEntitySlice> for Rc> { +impl From<&UniqueEntitySlice> for Rc> { fn from(value: &UniqueEntitySlice) -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_rc_slice_unchecked(value.0.into()) } } } -impl<'a, T: TrustedEntityBorrow + Clone> From<&'a UniqueEntitySlice> +impl<'a, T: EntityEquivalent + Clone> From<&'a UniqueEntitySlice> for Cow<'a, UniqueEntitySlice> { fn from(value: &'a UniqueEntitySlice) -> Self { @@ -1012,7 +1012,7 @@ impl<'a, T: TrustedEntityBorrow + Clone> From<&'a UniqueEntitySlice> } } -impl From> +impl From> for Box> { fn from(value: UniqueEntityArray) -> Self { @@ -1021,7 +1021,7 @@ impl From From>> +impl<'a, T: EntityEquivalent + Clone> From>> for Box> { fn from(value: Cow<'a, UniqueEntitySlice>) -> Self { @@ -1032,13 +1032,13 @@ impl<'a, T: TrustedEntityBorrow + Clone> From>> } } -impl From> for Box> { +impl From> for Box> { fn from(value: UniqueEntityVec) -> Self { value.into_boxed_slice() } } -impl FromIterator for Box> { +impl FromIterator for Box> { fn from_iter>(iter: I) -> Self { iter.into_iter() .collect::>() @@ -1046,7 +1046,7 @@ impl FromIterator for Box> { } } -impl FromEntitySetIterator for Box> { +impl FromEntitySetIterator for Box> { fn from_entity_set_iter>(iter: I) -> Self { iter.into_iter() .collect_set::>() @@ -1054,7 +1054,7 @@ impl FromEntitySetIterator for Box, U: TrustedEntityBorrow> PartialEq> +impl, U: EntityEquivalent> PartialEq> for &UniqueEntitySlice { fn eq(&self, other: &UniqueEntityVec) -> bool { @@ -1062,7 +1062,7 @@ impl, U: TrustedEntityBorrow> PartialEq, U: TrustedEntityBorrow> PartialEq> +impl, U: EntityEquivalent> PartialEq> for &mut UniqueEntitySlice { fn eq(&self, other: &UniqueEntityVec) -> bool { @@ -1070,7 +1070,7 @@ impl, U: TrustedEntityBorrow> PartialEq, U: TrustedEntityBorrow> PartialEq> +impl, U: EntityEquivalent> PartialEq> for UniqueEntitySlice { fn eq(&self, other: &UniqueEntityVec) -> bool { @@ -1078,7 +1078,7 @@ impl, U: TrustedEntityBorrow> PartialEq, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueEntitySlice> +impl, U: EntityEquivalent, const N: usize> PartialEq<&UniqueEntitySlice> for [T; N] { fn eq(&self, other: &&UniqueEntitySlice) -> bool { @@ -1086,7 +1086,7 @@ impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&UniqueE } } -impl + Clone, U: TrustedEntityBorrow> PartialEq<&UniqueEntitySlice> +impl + Clone, U: EntityEquivalent> PartialEq<&UniqueEntitySlice> for Cow<'_, [T]> { fn eq(&self, other: &&UniqueEntitySlice) -> bool { @@ -1094,7 +1094,7 @@ impl + Clone, U: TrustedEntityBorrow> PartialEq<&UniqueEntitySli } } -impl + Clone, U: TrustedEntityBorrow> +impl + Clone, U: EntityEquivalent> PartialEq<&UniqueEntitySlice> for Cow<'_, UniqueEntitySlice> { fn eq(&self, other: &&UniqueEntitySlice) -> bool { @@ -1102,19 +1102,19 @@ impl + Clone, U: TrustedEntityBorrow> } } -impl, U: TrustedEntityBorrow> PartialEq<&UniqueEntitySlice> for Vec { +impl, U: EntityEquivalent> PartialEq<&UniqueEntitySlice> for Vec { fn eq(&self, other: &&UniqueEntitySlice) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow> PartialEq<&UniqueEntitySlice> for VecDeque { +impl, U: EntityEquivalent> PartialEq<&UniqueEntitySlice> for VecDeque { fn eq(&self, other: &&UniqueEntitySlice) -> bool { self.eq(&&other.0) } } -impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&mut UniqueEntitySlice> +impl, U: EntityEquivalent, const N: usize> PartialEq<&mut UniqueEntitySlice> for [T; N] { fn eq(&self, other: &&mut UniqueEntitySlice) -> bool { @@ -1122,7 +1122,7 @@ impl, U: TrustedEntityBorrow, const N: usize> PartialEq<&mut Uni } } -impl + Clone, U: TrustedEntityBorrow> PartialEq<&mut UniqueEntitySlice> +impl + Clone, U: EntityEquivalent> PartialEq<&mut UniqueEntitySlice> for Cow<'_, [T]> { fn eq(&self, other: &&mut UniqueEntitySlice) -> bool { @@ -1130,7 +1130,7 @@ impl + Clone, U: TrustedEntityBorrow> PartialEq<&mut UniqueEntit } } -impl + Clone, U: TrustedEntityBorrow> +impl + Clone, U: EntityEquivalent> PartialEq<&mut UniqueEntitySlice> for Cow<'_, UniqueEntitySlice> { fn eq(&self, other: &&mut UniqueEntitySlice) -> bool { @@ -1138,27 +1138,27 @@ impl + Clone, U: TrustedEntityBorrow> } } -impl + Clone, U: TrustedEntityBorrow> - PartialEq> for Cow<'_, UniqueEntitySlice> +impl + Clone, U: EntityEquivalent> PartialEq> + for Cow<'_, UniqueEntitySlice> { fn eq(&self, other: &UniqueEntityVec) -> bool { self.0.eq(other.as_vec()) } } -impl, U: TrustedEntityBorrow> PartialEq<&mut UniqueEntitySlice> for Vec { +impl, U: EntityEquivalent> PartialEq<&mut UniqueEntitySlice> for Vec { fn eq(&self, other: &&mut UniqueEntitySlice) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow> PartialEq<&mut UniqueEntitySlice> for VecDeque { +impl, U: EntityEquivalent> PartialEq<&mut UniqueEntitySlice> for VecDeque { fn eq(&self, other: &&mut UniqueEntitySlice) -> bool { self.eq(&&other.0) } } -impl, U: TrustedEntityBorrow> PartialEq> +impl, U: EntityEquivalent> PartialEq> for [T] { fn eq(&self, other: &UniqueEntitySlice) -> bool { @@ -1166,7 +1166,7 @@ impl, U: TrustedEntityBorrow> PartialEq, U: TrustedEntityBorrow, const N: usize> PartialEq> +impl, U: EntityEquivalent, const N: usize> PartialEq> for [T; N] { fn eq(&self, other: &UniqueEntitySlice) -> bool { @@ -1174,7 +1174,7 @@ impl, U: TrustedEntityBorrow, const N: usize> PartialEq, U: TrustedEntityBorrow> PartialEq> +impl, U: EntityEquivalent> PartialEq> for Vec { fn eq(&self, other: &UniqueEntitySlice) -> bool { @@ -1182,7 +1182,7 @@ impl, U: TrustedEntityBorrow> PartialEq, U, const N: usize> PartialEq<[U; N]> +impl, U, const N: usize> PartialEq<[U; N]> for &UniqueEntitySlice { fn eq(&self, other: &[U; N]) -> bool { @@ -1190,7 +1190,7 @@ impl, U, const N: usize> PartialEq<[U; N]> } } -impl, U, const N: usize> PartialEq<[U; N]> +impl, U, const N: usize> PartialEq<[U; N]> for &mut UniqueEntitySlice { fn eq(&self, other: &[U; N]) -> bool { @@ -1198,7 +1198,7 @@ impl, U, const N: usize> PartialEq<[U; N]> } } -impl, U, const N: usize> PartialEq<[U; N]> +impl, U, const N: usize> PartialEq<[U; N]> for UniqueEntitySlice { fn eq(&self, other: &[U; N]) -> bool { @@ -1206,7 +1206,7 @@ impl, U, const N: usize> PartialEq<[U; N]> } } -impl, U: TrustedEntityBorrow, const N: usize> +impl, U: EntityEquivalent, const N: usize> PartialEq> for &UniqueEntitySlice { fn eq(&self, other: &UniqueEntityArray) -> bool { @@ -1214,7 +1214,7 @@ impl, U: TrustedEntityBorrow, const N: usi } } -impl, U: TrustedEntityBorrow, const N: usize> +impl, U: EntityEquivalent, const N: usize> PartialEq> for &mut UniqueEntitySlice { fn eq(&self, other: &UniqueEntityArray) -> bool { @@ -1222,7 +1222,7 @@ impl, U: TrustedEntityBorrow, const N: usi } } -impl, U: TrustedEntityBorrow, const N: usize> +impl, U: EntityEquivalent, const N: usize> PartialEq> for UniqueEntitySlice { fn eq(&self, other: &UniqueEntityArray) -> bool { @@ -1230,25 +1230,25 @@ impl, U: TrustedEntityBorrow, const N: usi } } -impl, U> PartialEq> for &UniqueEntitySlice { +impl, U> PartialEq> for &UniqueEntitySlice { fn eq(&self, other: &Vec) -> bool { self.0.eq(other) } } -impl, U> PartialEq> for &mut UniqueEntitySlice { +impl, U> PartialEq> for &mut UniqueEntitySlice { fn eq(&self, other: &Vec) -> bool { self.0.eq(other) } } -impl, U> PartialEq> for UniqueEntitySlice { +impl, U> PartialEq> for UniqueEntitySlice { fn eq(&self, other: &Vec) -> bool { self.0.eq(other) } } -impl ToOwned for UniqueEntitySlice { +impl ToOwned for UniqueEntitySlice { type Owned = UniqueEntityVec; fn to_owned(&self) -> Self::Owned { @@ -1257,7 +1257,7 @@ impl ToOwned for UniqueEntitySlice { } } -impl<'a, T: TrustedEntityBorrow + Copy, const N: usize> TryFrom<&'a UniqueEntitySlice> +impl<'a, T: EntityEquivalent + Copy, const N: usize> TryFrom<&'a UniqueEntitySlice> for &'a UniqueEntityArray { type Error = TryFromSliceError; @@ -1269,7 +1269,7 @@ impl<'a, T: TrustedEntityBorrow + Copy, const N: usize> TryFrom<&'a UniqueEntity } } -impl TryFrom<&UniqueEntitySlice> +impl TryFrom<&UniqueEntitySlice> for UniqueEntityArray { type Error = TryFromSliceError; @@ -1279,7 +1279,7 @@ impl TryFrom<&UniqueEntitySlice TryFrom<&mut UniqueEntitySlice> +impl TryFrom<&mut UniqueEntitySlice> for UniqueEntityArray { type Error = TryFromSliceError; @@ -1289,7 +1289,7 @@ impl TryFrom<&mut UniqueEntitySli } } -impl Index<(Bound, Bound)> for UniqueEntitySlice { +impl Index<(Bound, Bound)> for UniqueEntitySlice { type Output = Self; fn index(&self, key: (Bound, Bound)) -> &Self { // SAFETY: All elements in the original slice are unique. @@ -1297,7 +1297,7 @@ impl Index<(Bound, Bound)> for UniqueEntit } } -impl Index> for UniqueEntitySlice { +impl Index> for UniqueEntitySlice { type Output = Self; fn index(&self, key: Range) -> &Self { // SAFETY: All elements in the original slice are unique. @@ -1305,7 +1305,7 @@ impl Index> for UniqueEntitySlice { } } -impl Index> for UniqueEntitySlice { +impl Index> for UniqueEntitySlice { type Output = Self; fn index(&self, key: RangeFrom) -> &Self { // SAFETY: All elements in the original slice are unique. @@ -1313,7 +1313,7 @@ impl Index> for UniqueEntitySlice { } } -impl Index for UniqueEntitySlice { +impl Index for UniqueEntitySlice { type Output = Self; fn index(&self, key: RangeFull) -> &Self { // SAFETY: All elements in the original slice are unique. @@ -1321,7 +1321,7 @@ impl Index for UniqueEntitySlice { } } -impl Index> for UniqueEntitySlice { +impl Index> for UniqueEntitySlice { type Output = UniqueEntitySlice; fn index(&self, key: RangeInclusive) -> &Self { // SAFETY: All elements in the original slice are unique. @@ -1329,7 +1329,7 @@ impl Index> for UniqueEntitySlice< } } -impl Index> for UniqueEntitySlice { +impl Index> for UniqueEntitySlice { type Output = UniqueEntitySlice; fn index(&self, key: RangeTo) -> &Self { // SAFETY: All elements in the original slice are unique. @@ -1337,7 +1337,7 @@ impl Index> for UniqueEntitySlice { } } -impl Index> for UniqueEntitySlice { +impl Index> for UniqueEntitySlice { type Output = UniqueEntitySlice; fn index(&self, key: RangeToInclusive) -> &Self { // SAFETY: All elements in the original slice are unique. @@ -1345,7 +1345,7 @@ impl Index> for UniqueEntitySlic } } -impl Index for UniqueEntitySlice { +impl Index for UniqueEntitySlice { type Output = T; fn index(&self, index: usize) -> &T { @@ -1353,49 +1353,49 @@ impl Index for UniqueEntitySlice { } } -impl IndexMut<(Bound, Bound)> for UniqueEntitySlice { +impl IndexMut<(Bound, Bound)> for UniqueEntitySlice { fn index_mut(&mut self, key: (Bound, Bound)) -> &mut Self { // SAFETY: All elements in the original slice are unique. unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut> for UniqueEntitySlice { +impl IndexMut> for UniqueEntitySlice { fn index_mut(&mut self, key: Range) -> &mut Self { // SAFETY: All elements in the original slice are unique. unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut> for UniqueEntitySlice { +impl IndexMut> for UniqueEntitySlice { fn index_mut(&mut self, key: RangeFrom) -> &mut Self { // SAFETY: All elements in the original slice are unique. unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut for UniqueEntitySlice { +impl IndexMut for UniqueEntitySlice { fn index_mut(&mut self, key: RangeFull) -> &mut Self { // SAFETY: All elements in the original slice are unique. unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut> for UniqueEntitySlice { +impl IndexMut> for UniqueEntitySlice { fn index_mut(&mut self, key: RangeInclusive) -> &mut Self { // SAFETY: All elements in the original slice are unique. unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut> for UniqueEntitySlice { +impl IndexMut> for UniqueEntitySlice { fn index_mut(&mut self, key: RangeTo) -> &mut Self { // SAFETY: All elements in the original slice are unique. unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut> for UniqueEntitySlice { +impl IndexMut> for UniqueEntitySlice { fn index_mut(&mut self, key: RangeToInclusive) -> &mut Self { // SAFETY: All elements in the original slice are unique. unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) } @@ -1410,7 +1410,7 @@ impl IndexMut> for UniqueEntityS /// [`iter`]: `UniqueEntitySlice::iter` pub type Iter<'a, T> = UniqueEntityIter>; -impl<'a, T: TrustedEntityBorrow> UniqueEntityIter> { +impl<'a, T: EntityEquivalent> UniqueEntityIter> { /// Views the underlying data as a subslice of the original data. /// /// Equivalent to [`slice::Iter::as_slice`]. @@ -1423,7 +1423,7 @@ impl<'a, T: TrustedEntityBorrow> UniqueEntityIter> { /// Mutable slice iterator. pub type IterMut<'a, T> = UniqueEntityIter>; -impl<'a, T: TrustedEntityBorrow> UniqueEntityIter> { +impl<'a, T: EntityEquivalent> UniqueEntityIter> { /// Views the underlying data as a mutable subslice of the original data. /// /// Equivalent to [`slice::IterMut::into_slice`]. @@ -1444,11 +1444,11 @@ impl<'a, T: TrustedEntityBorrow> UniqueEntityIter> { /// An iterator that yields `&UniqueEntitySlice`. Note that an entity may appear /// in multiple slices, depending on the wrapped iterator. #[derive(Debug)] -pub struct UniqueEntitySliceIter<'a, T: TrustedEntityBorrow + 'a, I: Iterator> { +pub struct UniqueEntitySliceIter<'a, T: EntityEquivalent + 'a, I: Iterator> { pub(crate) iter: I, } -impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator> UniqueEntitySliceIter<'a, T, I> { +impl<'a, T: EntityEquivalent + 'a, I: Iterator> UniqueEntitySliceIter<'a, T, I> { /// Constructs a [`UniqueEntitySliceIter`] from a slice iterator unsafely. /// /// # Safety @@ -1479,7 +1479,7 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator> UniqueEntityS } } -impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator> Iterator +impl<'a, T: EntityEquivalent + 'a, I: Iterator> Iterator for UniqueEntitySliceIter<'a, T, I> { type Item = &'a UniqueEntitySlice; @@ -1495,12 +1495,12 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator> Iterator } } -impl<'a, T: TrustedEntityBorrow + 'a, I: ExactSizeIterator> ExactSizeIterator +impl<'a, T: EntityEquivalent + 'a, I: ExactSizeIterator> ExactSizeIterator for UniqueEntitySliceIter<'a, T, I> { } -impl<'a, T: TrustedEntityBorrow + 'a, I: DoubleEndedIterator> DoubleEndedIterator +impl<'a, T: EntityEquivalent + 'a, I: DoubleEndedIterator> DoubleEndedIterator for UniqueEntitySliceIter<'a, T, I> { fn next_back(&mut self) -> Option { @@ -1510,12 +1510,12 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: DoubleEndedIterator> Do } } -impl<'a, T: TrustedEntityBorrow + 'a, I: FusedIterator> FusedIterator +impl<'a, T: EntityEquivalent + 'a, I: FusedIterator> FusedIterator for UniqueEntitySliceIter<'a, T, I> { } -impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator + AsRef<[&'a [T]]>> +impl<'a, T: EntityEquivalent + 'a, I: Iterator + AsRef<[&'a [T]]>> AsRef<[&'a UniqueEntitySlice]> for UniqueEntitySliceIter<'a, T, I> { fn as_ref(&self) -> &[&'a UniqueEntitySlice] { @@ -1541,7 +1541,7 @@ pub type Chunks<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::Chunks<'a, /// This struct is created by [`UniqueEntitySlice::chunks_exact`]. pub type ChunksExact<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::ChunksExact<'a, T>>; -impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIter<'a, T, slice::ChunksExact<'a, T>> { +impl<'a, T: EntityEquivalent> UniqueEntitySliceIter<'a, T, slice::ChunksExact<'a, T>> { /// Returns the remainder of the original slice that is not going to be /// returned by the iterator. /// @@ -1564,7 +1564,7 @@ pub type RChunks<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::RChunks<' /// This struct is created by [`UniqueEntitySlice::rchunks_exact`]. pub type RChunksExact<'a, T = Entity> = UniqueEntitySliceIter<'a, T, slice::RChunksExact<'a, T>>; -impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIter<'a, T, slice::RChunksExact<'a, T>> { +impl<'a, T: EntityEquivalent> UniqueEntitySliceIter<'a, T, slice::RChunksExact<'a, T>> { /// Returns the remainder of the original slice that is not going to be /// returned by the iterator. /// @@ -1615,15 +1615,11 @@ pub type RSplitN<'a, P, T = Entity> = UniqueEntitySliceIter<'a, T, slice::RSplit /// An iterator that yields `&mut UniqueEntitySlice`. Note that an entity may appear /// in multiple slices, depending on the wrapped iterator. #[derive(Debug)] -pub struct UniqueEntitySliceIterMut< - 'a, - T: TrustedEntityBorrow + 'a, - I: Iterator, -> { +pub struct UniqueEntitySliceIterMut<'a, T: EntityEquivalent + 'a, I: Iterator> { pub(crate) iter: I, } -impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator> +impl<'a, T: EntityEquivalent + 'a, I: Iterator> UniqueEntitySliceIterMut<'a, T, I> { /// Constructs a [`UniqueEntitySliceIterMut`] from a mutable slice iterator unsafely. @@ -1656,7 +1652,7 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator> } } -impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator> Iterator +impl<'a, T: EntityEquivalent + 'a, I: Iterator> Iterator for UniqueEntitySliceIterMut<'a, T, I> { type Item = &'a mut UniqueEntitySlice; @@ -1672,13 +1668,13 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator> Iterator } } -impl<'a, T: TrustedEntityBorrow + 'a, I: ExactSizeIterator> ExactSizeIterator +impl<'a, T: EntityEquivalent + 'a, I: ExactSizeIterator> ExactSizeIterator for UniqueEntitySliceIterMut<'a, T, I> { } -impl<'a, T: TrustedEntityBorrow + 'a, I: DoubleEndedIterator> - DoubleEndedIterator for UniqueEntitySliceIterMut<'a, T, I> +impl<'a, T: EntityEquivalent + 'a, I: DoubleEndedIterator> DoubleEndedIterator + for UniqueEntitySliceIterMut<'a, T, I> { fn next_back(&mut self) -> Option { self.iter.next_back().map(|slice| @@ -1687,12 +1683,12 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: DoubleEndedIterator } } -impl<'a, T: TrustedEntityBorrow + 'a, I: FusedIterator> FusedIterator +impl<'a, T: EntityEquivalent + 'a, I: FusedIterator> FusedIterator for UniqueEntitySliceIterMut<'a, T, I> { } -impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator + AsRef<[&'a [T]]>> +impl<'a, T: EntityEquivalent + 'a, I: Iterator + AsRef<[&'a [T]]>> AsRef<[&'a UniqueEntitySlice]> for UniqueEntitySliceIterMut<'a, T, I> { fn as_ref(&self) -> &[&'a UniqueEntitySlice] { @@ -1701,7 +1697,7 @@ impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator + AsRef<[& } } -impl<'a, T: TrustedEntityBorrow + 'a, I: Iterator + AsMut<[&'a mut [T]]>> +impl<'a, T: EntityEquivalent + 'a, I: Iterator + AsMut<[&'a mut [T]]>> AsMut<[&'a mut UniqueEntitySlice]> for UniqueEntitySliceIterMut<'a, T, I> { fn as_mut(&mut self) -> &mut [&'a mut UniqueEntitySlice] { @@ -1723,7 +1719,7 @@ pub type ChunksMut<'a, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::Chun pub type ChunksExactMut<'a, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::ChunksExactMut<'a, T>>; -impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIterMut<'a, T, slice::ChunksExactMut<'a, T>> { +impl<'a, T: EntityEquivalent> UniqueEntitySliceIterMut<'a, T, slice::ChunksExactMut<'a, T>> { /// Returns the remainder of the original slice that is not going to be /// returned by the iterator. /// @@ -1747,7 +1743,7 @@ pub type RChunksMut<'a, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::RCh pub type RChunksExactMut<'a, T = Entity> = UniqueEntitySliceIterMut<'a, T, slice::RChunksExactMut<'a, T>>; -impl<'a, T: TrustedEntityBorrow> UniqueEntitySliceIterMut<'a, T, slice::RChunksExactMut<'a, T>> { +impl<'a, T: EntityEquivalent> UniqueEntitySliceIterMut<'a, T, slice::RChunksExactMut<'a, T>> { /// Returns the remainder of the original slice that is not going to be /// returned by the iterator. /// diff --git a/crates/bevy_ecs/src/entity/unique_vec.rs b/crates/bevy_ecs/src/entity/unique_vec.rs index 061cf820d1..4c4816b9ba 100644 --- a/crates/bevy_ecs/src/entity/unique_vec.rs +++ b/crates/bevy_ecs/src/entity/unique_vec.rs @@ -21,7 +21,7 @@ use bevy_platform_support::sync::Arc; use super::{ unique_slice::{self, UniqueEntitySlice}, - Entity, EntitySet, FromEntitySetIterator, TrustedEntityBorrow, UniqueEntityArray, + Entity, EntityEquivalent, EntitySet, FromEntitySetIterator, UniqueEntityArray, UniqueEntityIter, }; @@ -36,9 +36,9 @@ 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 { +impl UniqueEntityVec { /// Constructs a new, empty `UniqueEntityVec`. /// /// Equivalent to [`Vec::new`]. @@ -405,13 +405,13 @@ impl UniqueEntityVec { } } -impl Default for UniqueEntityVec { +impl Default for UniqueEntityVec { fn default() -> Self { Self(Vec::default()) } } -impl Deref for UniqueEntityVec { +impl Deref for UniqueEntityVec { type Target = UniqueEntitySlice; fn deref(&self) -> &Self::Target { @@ -420,16 +420,16 @@ impl Deref for UniqueEntityVec { } } -impl DerefMut for UniqueEntityVec { +impl DerefMut for UniqueEntityVec { fn deref_mut(&mut self) -> &mut Self::Target { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(&mut self.0) } } } -impl<'a, T: TrustedEntityBorrow> IntoIterator for &'a UniqueEntityVec +impl<'a, T: EntityEquivalent> IntoIterator for &'a UniqueEntityVec where - &'a T: TrustedEntityBorrow, + &'a T: EntityEquivalent, { type Item = &'a T; @@ -441,7 +441,7 @@ where } } -impl IntoIterator for UniqueEntityVec { +impl IntoIterator for UniqueEntityVec { type Item = T; type IntoIter = IntoIter; @@ -452,79 +452,79 @@ impl IntoIterator for UniqueEntityVec { } } -impl AsMut for UniqueEntityVec { +impl AsMut for UniqueEntityVec { fn as_mut(&mut self) -> &mut UniqueEntityVec { self } } -impl AsMut> for UniqueEntityVec { +impl AsMut> for UniqueEntityVec { fn as_mut(&mut self) -> &mut UniqueEntitySlice { self } } -impl AsRef for UniqueEntityVec { +impl AsRef for UniqueEntityVec { fn as_ref(&self) -> &Self { self } } -impl AsRef> for UniqueEntityVec { +impl AsRef> for UniqueEntityVec { fn as_ref(&self) -> &Vec { &self.0 } } -impl Borrow> for UniqueEntityVec { +impl Borrow> for UniqueEntityVec { fn borrow(&self) -> &Vec { &self.0 } } -impl AsRef<[T]> for UniqueEntityVec { +impl AsRef<[T]> for UniqueEntityVec { fn as_ref(&self) -> &[T] { &self.0 } } -impl AsRef> for UniqueEntityVec { +impl AsRef> for UniqueEntityVec { fn as_ref(&self) -> &UniqueEntitySlice { self } } -impl Borrow<[T]> for UniqueEntityVec { +impl Borrow<[T]> for UniqueEntityVec { fn borrow(&self) -> &[T] { &self.0 } } -impl Borrow> for UniqueEntityVec { +impl Borrow> for UniqueEntityVec { fn borrow(&self) -> &UniqueEntitySlice { self } } -impl BorrowMut> for UniqueEntityVec { +impl BorrowMut> for UniqueEntityVec { fn borrow_mut(&mut self) -> &mut UniqueEntitySlice { self } } -impl, U> PartialEq> for UniqueEntityVec { +impl, U> PartialEq> for UniqueEntityVec { fn eq(&self, other: &Vec) -> bool { self.0.eq(other) } } -impl, U> PartialEq<&[U]> for UniqueEntityVec { +impl, U> PartialEq<&[U]> for UniqueEntityVec { fn eq(&self, other: &&[U]) -> bool { self.0.eq(other) } } -impl, U: TrustedEntityBorrow> PartialEq<&UniqueEntitySlice> +impl, U: EntityEquivalent> PartialEq<&UniqueEntitySlice> for UniqueEntityVec { fn eq(&self, other: &&UniqueEntitySlice) -> bool { @@ -532,21 +532,21 @@ impl, U: TrustedEntityBorrow> PartialEq<&U } } -impl, U> PartialEq<&mut [U]> for UniqueEntityVec { +impl, U> PartialEq<&mut [U]> for UniqueEntityVec { fn eq(&self, other: &&mut [U]) -> bool { self.0.eq(other) } } -impl, U: TrustedEntityBorrow> - PartialEq<&mut UniqueEntitySlice> for UniqueEntityVec +impl, U: EntityEquivalent> PartialEq<&mut UniqueEntitySlice> + for UniqueEntityVec { fn eq(&self, other: &&mut UniqueEntitySlice) -> bool { self.0.eq(other) } } -impl, U, const N: usize> PartialEq<&[U; N]> +impl, U, const N: usize> PartialEq<&[U; N]> for UniqueEntityVec { fn eq(&self, other: &&[U; N]) -> bool { @@ -554,7 +554,7 @@ impl, U, const N: usize> PartialEq<&[U; N] } } -impl, U: TrustedEntityBorrow, const N: usize> +impl, U: EntityEquivalent, const N: usize> PartialEq<&UniqueEntityArray> for UniqueEntityVec { fn eq(&self, other: &&UniqueEntityArray) -> bool { @@ -562,7 +562,7 @@ impl, U: TrustedEntityBorrow, const N: usi } } -impl, U, const N: usize> PartialEq<&mut [U; N]> +impl, U, const N: usize> PartialEq<&mut [U; N]> for UniqueEntityVec { fn eq(&self, other: &&mut [U; N]) -> bool { @@ -570,7 +570,7 @@ impl, U, const N: usize> PartialEq<&mut [U } } -impl, U: TrustedEntityBorrow, const N: usize> +impl, U: EntityEquivalent, const N: usize> PartialEq<&mut UniqueEntityArray> for UniqueEntityVec { fn eq(&self, other: &&mut UniqueEntityArray) -> bool { @@ -578,13 +578,13 @@ impl, U: TrustedEntityBorrow, const N: usi } } -impl, U> PartialEq<[U]> for UniqueEntityVec { +impl, U> PartialEq<[U]> for UniqueEntityVec { fn eq(&self, other: &[U]) -> bool { self.0.eq(other) } } -impl, U: TrustedEntityBorrow> PartialEq> +impl, U: EntityEquivalent> PartialEq> for UniqueEntityVec { fn eq(&self, other: &UniqueEntitySlice) -> bool { @@ -592,7 +592,7 @@ impl, U: TrustedEntityBorrow> PartialEq, U, const N: usize> PartialEq<[U; N]> +impl, U, const N: usize> PartialEq<[U; N]> for UniqueEntityVec { fn eq(&self, other: &[U; N]) -> bool { @@ -600,7 +600,7 @@ impl, U, const N: usize> PartialEq<[U; N]> } } -impl, U: TrustedEntityBorrow, const N: usize> +impl, U: EntityEquivalent, const N: usize> PartialEq> for UniqueEntityVec { fn eq(&self, other: &UniqueEntityArray) -> bool { @@ -608,25 +608,25 @@ impl, U: TrustedEntityBorrow, const N: usi } } -impl, U: TrustedEntityBorrow> PartialEq> for Vec { +impl, U: EntityEquivalent> PartialEq> for Vec { fn eq(&self, other: &UniqueEntityVec) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow> PartialEq> for &[T] { +impl, U: EntityEquivalent> PartialEq> for &[T] { fn eq(&self, other: &UniqueEntityVec) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow> PartialEq> for &mut [T] { +impl, U: EntityEquivalent> PartialEq> for &mut [T] { fn eq(&self, other: &UniqueEntityVec) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow> PartialEq> +impl, U: EntityEquivalent> PartialEq> for [T] { fn eq(&self, other: &UniqueEntityVec) -> bool { @@ -634,39 +634,37 @@ impl, U: TrustedEntityBorrow> PartialEq + Clone, U: TrustedEntityBorrow> PartialEq> - for Cow<'_, [T]> -{ +impl + Clone, U: EntityEquivalent> PartialEq> for Cow<'_, [T]> { fn eq(&self, other: &UniqueEntityVec) -> bool { self.eq(&other.0) } } -impl, U: TrustedEntityBorrow> PartialEq> for VecDeque { +impl, U: EntityEquivalent> PartialEq> for VecDeque { fn eq(&self, other: &UniqueEntityVec) -> bool { self.eq(&other.0) } } -impl From<&UniqueEntitySlice> for UniqueEntityVec { +impl From<&UniqueEntitySlice> for UniqueEntityVec { fn from(value: &UniqueEntitySlice) -> Self { value.to_vec() } } -impl From<&mut UniqueEntitySlice> for UniqueEntityVec { +impl From<&mut UniqueEntitySlice> for UniqueEntityVec { fn from(value: &mut UniqueEntitySlice) -> Self { value.to_vec() } } -impl From>> for UniqueEntityVec { +impl From>> for UniqueEntityVec { fn from(value: Box>) -> Self { value.into_vec() } } -impl From>> for UniqueEntityVec +impl From>> for UniqueEntityVec where UniqueEntitySlice: ToOwned>, { @@ -675,43 +673,43 @@ where } } -impl From<&[T; 1]> for UniqueEntityVec { +impl From<&[T; 1]> for UniqueEntityVec { fn from(value: &[T; 1]) -> Self { Self(Vec::from(value)) } } -impl From<&[T; 0]> for UniqueEntityVec { +impl From<&[T; 0]> for UniqueEntityVec { fn from(value: &[T; 0]) -> Self { Self(Vec::from(value)) } } -impl From<&mut [T; 1]> for UniqueEntityVec { +impl From<&mut [T; 1]> for UniqueEntityVec { fn from(value: &mut [T; 1]) -> Self { Self(Vec::from(value)) } } -impl From<&mut [T; 0]> for UniqueEntityVec { +impl From<&mut [T; 0]> for UniqueEntityVec { fn from(value: &mut [T; 0]) -> Self { Self(Vec::from(value)) } } -impl From<[T; 1]> for UniqueEntityVec { +impl From<[T; 1]> for UniqueEntityVec { fn from(value: [T; 1]) -> Self { Self(Vec::from(value)) } } -impl From<[T; 0]> for UniqueEntityVec { +impl From<[T; 0]> for UniqueEntityVec { fn from(value: [T; 0]) -> Self { Self(Vec::from(value)) } } -impl From<&UniqueEntityArray> +impl From<&UniqueEntityArray> for UniqueEntityVec { fn from(value: &UniqueEntityArray) -> Self { @@ -719,7 +717,7 @@ impl From<&UniqueEntityArray From<&mut UniqueEntityArray> +impl From<&mut UniqueEntityArray> for UniqueEntityVec { fn from(value: &mut UniqueEntityArray) -> Self { @@ -727,77 +725,75 @@ impl From<&mut UniqueEntityArray } } -impl From> for UniqueEntityVec { +impl From> for UniqueEntityVec { fn from(value: UniqueEntityArray) -> Self { Self(Vec::from(value.into_inner())) } } -impl From> for Vec { +impl From> for Vec { fn from(value: UniqueEntityVec) -> Self { value.0 } } -impl<'a, T: TrustedEntityBorrow + Clone> From> for Cow<'a, [T]> { +impl<'a, T: EntityEquivalent + Clone> From> for Cow<'a, [T]> { fn from(value: UniqueEntityVec) -> Self { Cow::from(value.0) } } -impl<'a, T: TrustedEntityBorrow + Clone> From> - for Cow<'a, UniqueEntitySlice> -{ +impl<'a, T: EntityEquivalent + Clone> From> for Cow<'a, UniqueEntitySlice> { fn from(value: UniqueEntityVec) -> Self { Cow::Owned(value) } } -impl From> for Arc<[T]> { +impl From> for Arc<[T]> { fn from(value: UniqueEntityVec) -> Self { Arc::from(value.0) } } -impl From> for Arc> { +impl From> for Arc> { fn from(value: UniqueEntityVec) -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_arc_slice_unchecked(Arc::from(value.0)) } } } -impl From> for BinaryHeap { +impl From> for BinaryHeap { fn from(value: UniqueEntityVec) -> Self { BinaryHeap::from(value.0) } } -impl From> for Box<[T]> { +impl From> for Box<[T]> { fn from(value: UniqueEntityVec) -> Self { Box::from(value.0) } } -impl From> for Rc<[T]> { +impl From> for Rc<[T]> { fn from(value: UniqueEntityVec) -> Self { Rc::from(value.0) } } -impl From> for Rc> { +impl From> for Rc> { fn from(value: UniqueEntityVec) -> Self { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_rc_slice_unchecked(Rc::from(value.0)) } } } -impl From> for VecDeque { +impl From> for VecDeque { fn from(value: UniqueEntityVec) -> Self { VecDeque::from(value.0) } } -impl TryFrom> for Box<[T; N]> { +impl TryFrom> for Box<[T; N]> { type Error = UniqueEntityVec; fn try_from(value: UniqueEntityVec) -> Result { @@ -805,7 +801,7 @@ impl TryFrom> for Box } } -impl TryFrom> +impl TryFrom> for Box> { type Error = UniqueEntityVec; @@ -819,7 +815,7 @@ impl TryFrom> } } -impl TryFrom> for [T; N] { +impl TryFrom> for [T; N] { type Error = UniqueEntityVec; fn try_from(value: UniqueEntityVec) -> Result { @@ -827,9 +823,7 @@ impl TryFrom> for [T; } } -impl TryFrom> - for UniqueEntityArray -{ +impl TryFrom> for UniqueEntityArray { type Error = UniqueEntityVec; fn try_from(value: UniqueEntityVec) -> Result { @@ -841,13 +835,13 @@ impl TryFrom> } } -impl From> for UniqueEntityVec { +impl From> for UniqueEntityVec { fn from(value: BTreeSet) -> Self { Self(value.into_iter().collect::>()) } } -impl FromIterator for UniqueEntityVec { +impl FromIterator for UniqueEntityVec { /// This impl only uses `Eq` to validate uniqueness, resulting in O(n^2) complexity. /// It can make sense for very low N, or if `T` implements neither `Ord` nor `Hash`. /// When possible, use `FromEntitySetIterator::from_entity_iter` instead. @@ -866,14 +860,14 @@ impl FromIterator for UniqueEntityVec { } } -impl FromEntitySetIterator for UniqueEntityVec { +impl FromEntitySetIterator for UniqueEntityVec { fn from_entity_set_iter>(iter: I) -> Self { // SAFETY: `iter` is an `EntitySet`. unsafe { Self::from_vec_unchecked(Vec::from_iter(iter)) } } } -impl Extend for UniqueEntityVec { +impl Extend for UniqueEntityVec { /// Use with caution, because this impl only uses `Eq` to validate uniqueness, /// resulting in O(n^2) complexity. /// It can make sense for very low N, or if `T` implements neither `Ord` nor `Hash`. @@ -900,7 +894,7 @@ impl Extend for UniqueEntityVec { } } -impl<'a, T: TrustedEntityBorrow + Copy + 'a> Extend<&'a T> for UniqueEntityVec { +impl<'a, T: EntityEquivalent + Copy + 'a> Extend<&'a T> for UniqueEntityVec { /// Use with caution, because this impl only uses `Eq` to validate uniqueness, /// resulting in O(n^2) complexity. /// It can make sense for very low N, or if `T` implements neither `Ord` nor `Hash`. @@ -927,7 +921,7 @@ impl<'a, T: TrustedEntityBorrow + Copy + 'a> Extend<&'a T> for UniqueEntityVec Index<(Bound, Bound)> for UniqueEntityVec { +impl Index<(Bound, Bound)> for UniqueEntityVec { type Output = UniqueEntitySlice; fn index(&self, key: (Bound, Bound)) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -935,7 +929,7 @@ impl Index<(Bound, Bound)> for UniqueEntit } } -impl Index> for UniqueEntityVec { +impl Index> for UniqueEntityVec { type Output = UniqueEntitySlice; fn index(&self, key: Range) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -943,7 +937,7 @@ impl Index> for UniqueEntityVec { } } -impl Index> for UniqueEntityVec { +impl Index> for UniqueEntityVec { type Output = UniqueEntitySlice; fn index(&self, key: RangeFrom) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -951,7 +945,7 @@ impl Index> for UniqueEntityVec { } } -impl Index for UniqueEntityVec { +impl Index for UniqueEntityVec { type Output = UniqueEntitySlice; fn index(&self, key: RangeFull) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -959,7 +953,7 @@ impl Index for UniqueEntityVec { } } -impl Index> for UniqueEntityVec { +impl Index> for UniqueEntityVec { type Output = UniqueEntitySlice; fn index(&self, key: RangeInclusive) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -967,7 +961,7 @@ impl Index> for UniqueEntityVec } } -impl Index> for UniqueEntityVec { +impl Index> for UniqueEntityVec { type Output = UniqueEntitySlice; fn index(&self, key: RangeTo) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -975,7 +969,7 @@ impl Index> for UniqueEntityVec { } } -impl Index> for UniqueEntityVec { +impl Index> for UniqueEntityVec { type Output = UniqueEntitySlice; fn index(&self, key: RangeToInclusive) -> &Self::Output { // SAFETY: All elements in the original slice are unique. @@ -983,56 +977,56 @@ impl Index> for UniqueEntityVec< } } -impl Index for UniqueEntityVec { +impl Index for UniqueEntityVec { type Output = T; fn index(&self, key: usize) -> &T { self.0.index(key) } } -impl IndexMut<(Bound, Bound)> for UniqueEntityVec { +impl IndexMut<(Bound, Bound)> for UniqueEntityVec { fn index_mut(&mut self, key: (Bound, Bound)) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut> for UniqueEntityVec { +impl IndexMut> for UniqueEntityVec { 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)) } } } -impl IndexMut> for UniqueEntityVec { +impl IndexMut> for UniqueEntityVec { fn index_mut(&mut self, key: RangeFrom) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut for UniqueEntityVec { +impl IndexMut for UniqueEntityVec { 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)) } } } -impl IndexMut> for UniqueEntityVec { +impl IndexMut> for UniqueEntityVec { fn index_mut(&mut self, key: RangeInclusive) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.0.index_mut(key)) } } } -impl IndexMut> for UniqueEntityVec { +impl IndexMut> for UniqueEntityVec { 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)) } } } -impl IndexMut> for UniqueEntityVec { +impl IndexMut> for UniqueEntityVec { fn index_mut(&mut self, key: RangeToInclusive) -> &mut Self::Output { // SAFETY: All elements in the original slice are unique. unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.0.index_mut(key)) } @@ -1045,7 +1039,7 @@ impl IndexMut> for UniqueEntityV /// method on [`UniqueEntityVec`]. pub type IntoIter = UniqueEntityIter>; -impl UniqueEntityIter> { +impl UniqueEntityIter> { /// Returns the remaining items of this iterator as a slice. /// /// Equivalent to [`vec::IntoIter::as_slice`]. @@ -1069,7 +1063,7 @@ impl UniqueEntityIter> { /// See its documentation for more. pub type Drain<'a, T = Entity> = UniqueEntityIter>; -impl<'a, T: TrustedEntityBorrow> UniqueEntityIter> { +impl<'a, T: EntityEquivalent> UniqueEntityIter> { /// Returns the remaining items of this iterator as a slice. /// /// Equivalent to [`vec::Drain::as_slice`]. diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 612e32b492..79ba938f4b 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -73,7 +73,7 @@ pub mod prelude { change_detection::{DetectChanges, DetectChangesMut, Mut, Ref}, children, component::Component, - entity::{Entity, EntityBorrow, EntityMapper}, + entity::{ContainsEntity, Entity, EntityMapper}, error::{BevyError, Result}, event::{Event, EventMutator, EventReader, EventWriter, Events}, hierarchy::{ChildOf, ChildSpawner, ChildSpawnerCommands, Children}, diff --git a/crates/bevy_ecs/src/query/iter.rs b/crates/bevy_ecs/src/query/iter.rs index 1e5dca4fb1..fc89843493 100644 --- a/crates/bevy_ecs/src/query/iter.rs +++ b/crates/bevy_ecs/src/query/iter.rs @@ -3,7 +3,7 @@ use crate::{ archetype::{Archetype, ArchetypeEntity, Archetypes}, bundle::Bundle, component::Tick, - entity::{Entities, Entity, EntityBorrow, EntitySet, EntitySetIterator}, + entity::{ContainsEntity, Entities, Entity, EntityEquivalent, EntitySet, EntitySetIterator}, query::{ArchetypeFilter, DebugCheckedUnwrap, QueryState, StorageId}, storage::{Table, TableRow, Tables}, world::{ @@ -1117,7 +1117,8 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> Debug /// Entities that don't match the query are skipped. /// /// This struct is created by the [`Query::iter_many`](crate::system::Query::iter_many) and [`Query::iter_many_mut`](crate::system::Query::iter_many_mut) methods. -pub struct QueryManyIter<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> { +pub struct QueryManyIter<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> +{ world: UnsafeWorldCell<'w>, entity_iter: I, entities: &'w Entities, @@ -1128,7 +1129,7 @@ pub struct QueryManyIter<'w, 's, D: QueryData, F: QueryFilter, I: Iterator, } -impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> +impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> QueryManyIter<'w, 's, D, F, I> { /// # Safety @@ -1167,7 +1168,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> /// It is always safe for shared access. #[inline(always)] unsafe fn fetch_next_aliased_unchecked( - entity_iter: impl Iterator, + entity_iter: impl Iterator, entities: &'w Entities, tables: &'w Tables, archetypes: &'w Archetypes, @@ -1720,7 +1721,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> } } -impl<'w, 's, D: QueryData, F: QueryFilter, I: DoubleEndedIterator> +impl<'w, 's, D: QueryData, F: QueryFilter, I: DoubleEndedIterator> QueryManyIter<'w, 's, D, F, I> { /// Get next result from the back of the query @@ -1746,7 +1747,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: DoubleEndedIterator> Iterator +impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator> Iterator for QueryManyIter<'w, 's, D, F, I> { type Item = D::Item<'w>; @@ -1775,8 +1776,13 @@ impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator> - DoubleEndedIterator for QueryManyIter<'w, 's, D, F, I> +impl< + 'w, + 's, + D: ReadOnlyQueryData, + F: QueryFilter, + I: DoubleEndedIterator, + > DoubleEndedIterator for QueryManyIter<'w, 's, D, F, I> { #[inline(always)] fn next_back(&mut self) -> Option { @@ -1798,8 +1804,8 @@ impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: DoubleEndedIterator> FusedIterator - for QueryManyIter<'w, 's, D, F, I> +impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator> + FusedIterator for QueryManyIter<'w, 's, D, F, I> { } @@ -1809,7 +1815,7 @@ unsafe impl<'w, 's, F: QueryFilter, I: EntitySetIterator> EntitySetIterator { } -impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> Debug +impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> Debug for QueryManyIter<'w, 's, D, F, I> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { diff --git a/crates/bevy_ecs/src/query/par_iter.rs b/crates/bevy_ecs/src/query/par_iter.rs index 0805774f8c..2e9824ef87 100644 --- a/crates/bevy_ecs/src/query/par_iter.rs +++ b/crates/bevy_ecs/src/query/par_iter.rs @@ -1,7 +1,7 @@ use crate::{ batching::BatchingStrategy, component::Tick, - entity::{EntityBorrow, TrustedEntityBorrow, UniqueEntityVec}, + entity::{EntityEquivalent, UniqueEntityVec}, world::unsafe_world_cell::UnsafeWorldCell, }; @@ -160,7 +160,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryParIter<'w, 's, D, F> { /// /// [`Entity`]: crate::entity::Entity /// [`Query::par_iter_many`]: crate::system::Query::par_iter_many -pub struct QueryParManyIter<'w, 's, D: QueryData, F: QueryFilter, E: EntityBorrow> { +pub struct QueryParManyIter<'w, 's, D: QueryData, F: QueryFilter, E: EntityEquivalent> { pub(crate) world: UnsafeWorldCell<'w>, pub(crate) state: &'s QueryState, pub(crate) entity_list: Vec, @@ -169,7 +169,7 @@ pub struct QueryParManyIter<'w, 's, D: QueryData, F: QueryFilter, E: EntityBorro pub(crate) batching_strategy: BatchingStrategy, } -impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, E: EntityBorrow + Sync> +impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, E: EntityEquivalent + Sync> QueryParManyIter<'w, 's, D, F, E> { /// Changes the batching strategy used when iterating. @@ -314,13 +314,8 @@ impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, E: EntityBorrow + Sync> /// [`EntitySet`]: crate::entity::EntitySet /// [`Query::par_iter_many_unique`]: crate::system::Query::par_iter_many_unique /// [`Query::par_iter_many_unique_mut`]: crate::system::Query::par_iter_many_unique_mut -pub struct QueryParManyUniqueIter< - 'w, - 's, - D: QueryData, - F: QueryFilter, - E: TrustedEntityBorrow + Sync, -> { +pub struct QueryParManyUniqueIter<'w, 's, D: QueryData, F: QueryFilter, E: EntityEquivalent + Sync> +{ pub(crate) world: UnsafeWorldCell<'w>, pub(crate) state: &'s QueryState, pub(crate) entity_list: UniqueEntityVec, @@ -329,7 +324,7 @@ pub struct QueryParManyUniqueIter< pub(crate) batching_strategy: BatchingStrategy, } -impl<'w, 's, D: QueryData, F: QueryFilter, E: TrustedEntityBorrow + Sync> +impl<'w, 's, D: QueryData, F: QueryFilter, E: EntityEquivalent + Sync> QueryParManyUniqueIter<'w, 's, D, F, E> { /// Changes the batching strategy used when iterating. diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 922b8d22f5..7a875b6532 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -1,7 +1,7 @@ use crate::{ archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId}, component::{ComponentId, Tick}, - entity::{Entity, EntityBorrow, EntitySet, UniqueEntityArray}, + entity::{Entity, EntityEquivalent, EntitySet, UniqueEntityArray}, entity_disabling::DefaultQueryFilters, prelude::FromWorld, query::{Access, FilteredAccess, QueryCombinationIter, QueryIter, QueryParIter, WorldQuery}, @@ -11,7 +11,7 @@ use crate::{ }; #[cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded"))] -use crate::entity::{TrustedEntityBorrow, UniqueEntitySlice}; +use crate::entity::UniqueEntitySlice; use alloc::vec::Vec; use core::{fmt, ptr}; @@ -1273,7 +1273,7 @@ impl QueryState { /// /// - [`iter_many_mut`](Self::iter_many_mut) to get mutable query items. #[inline] - pub fn iter_many<'w, 's, EntityList: IntoIterator>( + pub fn iter_many<'w, 's, EntityList: IntoIterator>( &'s mut self, world: &'w World, entities: EntityList, @@ -1296,7 +1296,7 @@ impl QueryState { /// - [`iter_many`](Self::iter_many) to update archetypes. /// - [`iter_manual`](Self::iter_manual) to iterate over all query items. #[inline] - pub fn iter_many_manual<'w, 's, EntityList: IntoIterator>( + pub fn iter_many_manual<'w, 's, EntityList: IntoIterator>( &'s self, world: &'w World, entities: EntityList, @@ -1309,7 +1309,7 @@ impl QueryState { /// Items are returned in the order of the list of entities. /// Entities that don't match the query are skipped. #[inline] - pub fn iter_many_mut<'w, 's, EntityList: IntoIterator>( + pub fn iter_many_mut<'w, 's, EntityList: IntoIterator>( &'s mut self, world: &'w mut World, entities: EntityList, @@ -1614,7 +1614,7 @@ impl QueryState { ) where FN: Fn(T, D::Item<'w>) -> T + Send + Sync + Clone, INIT: Fn() -> T + Sync + Send + Clone, - E: TrustedEntityBorrow + Sync, + E: EntityEquivalent + Sync, { // NOTE: If you are changing query iteration code, remember to update the following places, where relevant: // QueryIter, QueryIterationCursor, QueryManyIter, QueryCombinationIter,QueryState::par_fold_init_unchecked_manual @@ -1677,7 +1677,7 @@ impl QueryState { ) where FN: Fn(T, D::Item<'w>) -> T + Send + Sync + Clone, INIT: Fn() -> T + Sync + Send + Clone, - E: EntityBorrow + Sync, + E: EntityEquivalent + Sync, { // NOTE: If you are changing query iteration code, remember to update the following places, where relevant: // QueryIter, QueryIterationCursor, QueryManyIter, QueryCombinationIter, QueryState::par_fold_init_unchecked_manual diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index 629ce2ed50..7b14e603a3 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -1,7 +1,7 @@ use crate::{ batching::BatchingStrategy, component::Tick, - entity::{Entity, EntityBorrow, EntityDoesNotExistError, EntitySet, UniqueEntityArray}, + entity::{Entity, EntityDoesNotExistError, EntityEquivalent, EntitySet, UniqueEntityArray}, query::{ DebugCheckedUnwrap, NopWorldQuery, QueryCombinationIter, QueryData, QueryEntityError, QueryFilter, QueryIter, QueryManyIter, QueryManyUniqueIter, QueryParIter, QueryParManyIter, @@ -725,7 +725,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { /// - [`iter_many_mut`](Self::iter_many_mut) to get mutable query items. /// - [`iter_many_inner`](Self::iter_many_inner) to get mutable query items with the full `'world` lifetime. #[inline] - pub fn iter_many>( + pub fn iter_many>( &self, entities: EntityList, ) -> QueryManyIter<'_, 's, D::ReadOnly, F, EntityList::IntoIter> { @@ -770,7 +770,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { /// - [`iter_many`](Self::iter_many) to get read-only query items. /// - [`iter_many_inner`](Self::iter_many_inner) to get mutable query items with the full `'world` lifetime. #[inline] - pub fn iter_many_mut>( + pub fn iter_many_mut>( &mut self, entities: EntityList, ) -> QueryManyIter<'_, 's, D, F, EntityList::IntoIter> { @@ -788,7 +788,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { /// - [`iter_many`](Self::iter_many) to get read-only query items. /// - [`iter_many_mut`](Self::iter_many_mut) to get mutable query items. #[inline] - pub fn iter_many_inner>( + pub fn iter_many_inner>( self, entities: EntityList, ) -> QueryManyIter<'w, 's, D, F, EntityList::IntoIter> { @@ -1033,7 +1033,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { /// # See also /// /// - [`iter_many_mut`](Self::iter_many_mut) to safely access the query items. - pub unsafe fn iter_many_unsafe>( + pub unsafe fn iter_many_unsafe>( &self, entities: EntityList, ) -> QueryManyIter<'_, 's, D, F, EntityList::IntoIter> { @@ -1171,7 +1171,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { /// [`par_iter_many_unique_mut`]: Self::par_iter_many_unique_mut /// [`par_iter_mut`]: Self::par_iter_mut #[inline] - pub fn par_iter_many>( + pub fn par_iter_many>( &self, entities: EntityList, ) -> QueryParManyIter<'_, '_, D::ReadOnly, F, EntityList::Item> { diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index ab2788898f..22383e86b3 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -10,8 +10,8 @@ use crate::{ StorageType, }, entity::{ - Entities, Entity, EntityBorrow, EntityCloner, EntityClonerBuilder, EntityLocation, - TrustedEntityBorrow, + ContainsEntity, Entities, Entity, EntityCloner, EntityClonerBuilder, EntityEquivalent, + EntityLocation, }, event::Event, observer::Observer, @@ -415,14 +415,14 @@ impl Hash for EntityRef<'_> { } } -impl EntityBorrow for EntityRef<'_> { +impl ContainsEntity for EntityRef<'_> { fn entity(&self) -> Entity { self.id() } } // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity. -unsafe impl TrustedEntityBorrow for EntityRef<'_> {} +unsafe impl EntityEquivalent for EntityRef<'_> {} /// Provides mutable access to a single entity and all of its components. /// @@ -1066,14 +1066,14 @@ impl Hash for EntityMut<'_> { } } -impl EntityBorrow for EntityMut<'_> { +impl ContainsEntity for EntityMut<'_> { fn entity(&self) -> Entity { self.id() } } // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity. -unsafe impl TrustedEntityBorrow for EntityMut<'_> {} +unsafe impl EntityEquivalent for EntityMut<'_> {} /// A mutable reference to a particular [`Entity`], and the entire world. /// @@ -3644,14 +3644,14 @@ impl Hash for FilteredEntityRef<'_> { } } -impl EntityBorrow for FilteredEntityRef<'_> { +impl ContainsEntity for FilteredEntityRef<'_> { fn entity(&self) -> Entity { self.id() } } // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity. -unsafe impl TrustedEntityBorrow for FilteredEntityRef<'_> {} +unsafe impl EntityEquivalent for FilteredEntityRef<'_> {} /// Provides mutable access to a single entity and some of its components defined by the contained [`Access`]. /// @@ -3987,14 +3987,14 @@ impl Hash for FilteredEntityMut<'_> { } } -impl EntityBorrow for FilteredEntityMut<'_> { +impl ContainsEntity for FilteredEntityMut<'_> { fn entity(&self) -> Entity { self.id() } } // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity. -unsafe impl TrustedEntityBorrow for FilteredEntityMut<'_> {} +unsafe impl EntityEquivalent for FilteredEntityMut<'_> {} /// Error type returned by [`TryFrom`] conversions from filtered entity types /// ([`FilteredEntityRef`]/[`FilteredEntityMut`]) to full-access entity types @@ -4220,14 +4220,14 @@ impl Hash for EntityRefExcept<'_, B> { } } -impl EntityBorrow for EntityRefExcept<'_, B> { +impl ContainsEntity for EntityRefExcept<'_, B> { fn entity(&self) -> Entity { self.id() } } // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity. -unsafe impl TrustedEntityBorrow for EntityRefExcept<'_, B> {} +unsafe impl EntityEquivalent for EntityRefExcept<'_, B> {} /// Provides mutable access to all components of an entity, with the exception /// of an explicit set. @@ -4430,14 +4430,14 @@ impl Hash for EntityMutExcept<'_, B> { } } -impl EntityBorrow for EntityMutExcept<'_, B> { +impl ContainsEntity for EntityMutExcept<'_, B> { fn entity(&self) -> Entity { self.id() } } // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity. -unsafe impl TrustedEntityBorrow for EntityMutExcept<'_, B> {} +unsafe impl EntityEquivalent for EntityMutExcept<'_, B> {} fn bundle_contains_component(components: &Components, query_id: ComponentId) -> bool where diff --git a/crates/bevy_ecs/src/world/unsafe_world_cell.rs b/crates/bevy_ecs/src/world/unsafe_world_cell.rs index 8bca668ffc..681ac99c9b 100644 --- a/crates/bevy_ecs/src/world/unsafe_world_cell.rs +++ b/crates/bevy_ecs/src/world/unsafe_world_cell.rs @@ -6,7 +6,7 @@ use crate::{ bundle::Bundles, change_detection::{MaybeLocation, MutUntyped, Ticks, TicksMut}, component::{ComponentId, ComponentTicks, Components, Mutable, StorageType, Tick, TickCells}, - entity::{Entities, Entity, EntityBorrow, EntityDoesNotExistError, EntityLocation}, + entity::{ContainsEntity, Entities, Entity, EntityDoesNotExistError, EntityLocation}, observer::Observers, prelude::Component, query::{DebugCheckedUnwrap, ReadOnlyQueryData}, @@ -1273,7 +1273,7 @@ unsafe fn get_ticks( } } -impl EntityBorrow for UnsafeEntityCell<'_> { +impl ContainsEntity for UnsafeEntityCell<'_> { fn entity(&self) -> Entity { self.id() } diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs old mode 100644 new mode 100755 diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index d38cb3fbca..7bbfb8a60e 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -23,7 +23,7 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ change_detection::DetectChanges, component::{Component, HookContext}, - entity::{Entity, EntityBorrow}, + entity::{ContainsEntity, Entity}, event::EventReader, prelude::With, query::Has, diff --git a/crates/bevy_render/src/camera/camera_driver_node.rs b/crates/bevy_render/src/camera/camera_driver_node.rs index 7fa221235f..c78a41ed76 100644 --- a/crates/bevy_render/src/camera/camera_driver_node.rs +++ b/crates/bevy_render/src/camera/camera_driver_node.rs @@ -4,7 +4,7 @@ use crate::{ renderer::RenderContext, view::ExtractedWindows, }; -use bevy_ecs::{entity::EntityBorrow, prelude::QueryState, world::World}; +use bevy_ecs::{entity::ContainsEntity, prelude::QueryState, world::World}; use bevy_platform_support::collections::HashSet; use wgpu::{LoadOp, Operations, RenderPassColorAttachment, RenderPassDescriptor, StoreOp}; diff --git a/crates/bevy_render/src/sync_world.rs b/crates/bevy_render/src/sync_world.rs index 4f21e22bf9..7bb74c5cab 100644 --- a/crates/bevy_render/src/sync_world.rs +++ b/crates/bevy_render/src/sync_world.rs @@ -3,7 +3,7 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::entity::EntityHash; use bevy_ecs::{ component::Component, - entity::{Entity, EntityBorrow, TrustedEntityBorrow}, + entity::{ContainsEntity, Entity, EntityEquivalent}, observer::Trigger, query::With, reflect::ReflectComponent, @@ -141,14 +141,14 @@ impl From for RenderEntity { } } -impl EntityBorrow for RenderEntity { +impl ContainsEntity for RenderEntity { fn entity(&self) -> Entity { self.id() } } // SAFETY: RenderEntity is a newtype around Entity that derives its comparison traits. -unsafe impl TrustedEntityBorrow for RenderEntity {} +unsafe impl EntityEquivalent for RenderEntity {} /// Component added on the render world entities to keep track of the corresponding main world entity. /// @@ -168,14 +168,14 @@ impl From for MainEntity { } } -impl EntityBorrow for MainEntity { +impl ContainsEntity for MainEntity { fn entity(&self) -> Entity { self.id() } } // SAFETY: RenderEntity is a newtype around Entity that derives its comparison traits. -unsafe impl TrustedEntityBorrow for MainEntity {} +unsafe impl EntityEquivalent for MainEntity {} /// A [`HashMap`] pre-configured to use [`EntityHash`] hashing with a [`MainEntity`]. pub type MainEntityHashMap = HashMap; diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 92c262d93c..c974ab1be5 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -1,7 +1,7 @@ use crate::{CalculatedClip, ComputedNode, ComputedNodeTarget, ResolvedBorderRadius, UiStack}; use bevy_ecs::{ change_detection::DetectChangesMut, - entity::{Entity, EntityBorrow}, + entity::{ContainsEntity, Entity}, prelude::{Component, With}, query::QueryData, reflect::ReflectComponent, diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index b0f4a8183e..44eee7cb9c 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -2,7 +2,7 @@ use alloc::{borrow::ToOwned, format, string::String}; use core::num::NonZero; use bevy_ecs::{ - entity::{Entity, EntityBorrow}, + entity::{ContainsEntity, Entity}, prelude::Component, }; use bevy_math::{CompassOctant, DVec2, IVec2, UVec2, Vec2}; @@ -110,7 +110,7 @@ impl WindowRef { )] pub struct NormalizedWindowRef(Entity); -impl EntityBorrow for NormalizedWindowRef { +impl ContainsEntity for NormalizedWindowRef { fn entity(&self) -> Entity { self.0 }