From feedfa5470697a692d577c728c268436b974fa90 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 16:10:35 -0800 Subject: [PATCH 01/12] Add a test for Vec-based relationship source collections --- .../relationship_source_collection.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs index 0158f05f4b457..d06e4ed58cffe 100644 --- a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs +++ b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs @@ -49,3 +49,32 @@ impl RelationshipSourceCollection for Vec { Vec::len(self) } } + +#[cfg(test)] +mod tests { + use super::*; + use crate as bevy_ecs; + use crate::prelude::{Component, World}; + use crate::relationship::RelationshipTarget; + + #[test] + fn vec_relationship_source_collection() { + #[derive(Component)] + #[relationship(relationship_target = RelTarget)] + struct Rel(Entity); + + #[derive(Component)] + #[relationship_target(relationship = Rel, despawn_descendants)] + struct RelTarget(Vec); + + let mut world = World::new(); + let a = world.spawn_empty().id(); + let b = world.spawn_empty().id(); + + world.entity_mut(a).insert(Rel(b)); + + let rel_target = world.get::(b).unwrap(); + let collection = rel_target.collection(); + assert_eq!(collection, &alloc::vec!(a)); + } +} From 241feb93f494321ac3af7d24dfd6f42362a5dc8d Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 16:42:42 -0800 Subject: [PATCH 02/12] impl RelationshipSourceCollection for EntityHashSet --- crates/bevy_ecs/src/entity/hash_set.rs | 19 ++++++++++++++ .../relationship_source_collection.rs | 26 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/entity/hash_set.rs b/crates/bevy_ecs/src/entity/hash_set.rs index 12538d873b5c9..e3f9a669de214 100644 --- a/crates/bevy_ecs/src/entity/hash_set.rs +++ b/crates/bevy_ecs/src/entity/hash_set.rs @@ -38,6 +38,16 @@ impl EntityHashSet { Self(HashSet::with_capacity_and_hasher(n, EntityHash)) } + /// Returns the number of elements in the set. + pub fn len(&self) -> usize { + self.0.len() + } + + /// Returns `true` if the set contains no elements. + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + /// Returns the inner [`HashSet`]. pub fn into_inner(self) -> HashSet { self.0 @@ -221,6 +231,15 @@ impl ExactSizeIterator for Iter<'_> {} impl FusedIterator for Iter<'_> {} +/// This implementation is somewhat surprising: +/// as hash sets make no guarantees about the order of their elements, +/// [`DoubleEndedIterator::next_back`] is implemented by simply forwarding to the underlying [`Iter::next`]. +impl DoubleEndedIterator for Iter<'_> { + fn next_back(&mut self) -> Option { + self.0.next() + } +} + impl Clone for Iter<'_> { fn clone(&self) -> Self { Self(self.0.clone(), PhantomData) diff --git a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs index d06e4ed58cffe..2376a52b34b58 100644 --- a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs +++ b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs @@ -1,4 +1,4 @@ -use crate::entity::Entity; +use crate::entity::{Entity, EntityHashSet}; use alloc::vec::Vec; /// The internal [`Entity`] collection used by a [`RelationshipTarget`](crate::relationship::RelationshipTarget) component. @@ -50,6 +50,30 @@ impl RelationshipSourceCollection for Vec { } } +impl RelationshipSourceCollection for EntityHashSet { + fn with_capacity(capacity: usize) -> Self { + EntityHashSet::with_capacity(capacity) + } + + fn add(&mut self, entity: Entity) { + self.insert(entity); + } + + fn remove(&mut self, entity: Entity) { + // We need to call the remove method on the underlying hash set, + // which takes its argument by reference + self.0.remove(&entity); + } + + fn iter(&self) -> impl DoubleEndedIterator { + self.iter().copied() + } + + fn len(&self) -> usize { + self.len() + } +} + #[cfg(test)] mod tests { use super::*; From 36efe63685d530c03ea6db2313ad88be421e92e0 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 17:01:35 -0800 Subject: [PATCH 03/12] Docs for RelationshipTarget::Collection --- crates/bevy_ecs/src/relationship/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/bevy_ecs/src/relationship/mod.rs b/crates/bevy_ecs/src/relationship/mod.rs index 54105c0d7391d..84d8bdcd0bf61 100644 --- a/crates/bevy_ecs/src/relationship/mod.rs +++ b/crates/bevy_ecs/src/relationship/mod.rs @@ -136,6 +136,11 @@ pub trait RelationshipTarget: Component + Sized { /// The [`Relationship`] that populates this [`RelationshipTarget`] collection. type Relationship: Relationship; /// The collection type that stores the "source" entities for this [`RelationshipTarget`] component. + /// + /// Check the list of types which implement [`RelationshipSourceCollection`] for the data structures that can be used inside of your component. + /// If you need a new collection type, you can implement the [`RelationshipSourceCollection`] trait + /// for a type you own which wraps the collection you want to use (to avoid the orphan rule), + /// or open an issue on the Bevy repository to request first-party support for your collection type. type Collection: RelationshipSourceCollection; /// Returns a reference to the stored [`RelationshipTarget::Collection`]. From e4add92e28dc496cd121c89965ffa95f874e4880 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 17:01:45 -0800 Subject: [PATCH 04/12] Test for HashSet collections --- .../relationship_source_collection.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs index 2376a52b34b58..27efd9ed80532 100644 --- a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs +++ b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs @@ -101,4 +101,25 @@ mod tests { let collection = rel_target.collection(); assert_eq!(collection, &alloc::vec!(a)); } + + #[test] + fn entity_hash_set_relationship_source_collection() { + #[derive(Component)] + #[relationship(relationship_target = RelTarget)] + struct Rel(Entity); + + #[derive(Component)] + #[relationship_target(relationship = Rel, despawn_descendants)] + struct RelTarget(EntityHashSet); + + let mut world = World::new(); + let a = world.spawn_empty().id(); + let b = world.spawn_empty().id(); + + world.entity_mut(a).insert(Rel(b)); + + let rel_target = world.get::(b).unwrap(); + let collection = rel_target.collection(); + assert_eq!(collection, &EntityHashSet::from([a])); + } } From 0955a157cd880c060665e753b2e4bf851b413da9 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 19:11:44 -0800 Subject: [PATCH 05/12] Remove the need for Collection's iterator to impl DoubleEndedIterator by moving the trait bound to methods that need it --- crates/bevy_ecs/src/entity/hash_set.rs | 32 +++++++++---------- crates/bevy_ecs/src/entity/mod.rs | 2 +- crates/bevy_ecs/src/relationship/mod.rs | 5 ++- .../src/relationship/relationship_query.rs | 10 ++++++ .../relationship_source_collection.rs | 19 +++++++++-- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/crates/bevy_ecs/src/entity/hash_set.rs b/crates/bevy_ecs/src/entity/hash_set.rs index e3f9a669de214..0950380c26633 100644 --- a/crates/bevy_ecs/src/entity/hash_set.rs +++ b/crates/bevy_ecs/src/entity/hash_set.rs @@ -64,8 +64,8 @@ impl EntityHashSet { /// The iterator element type is `&'a Entity`. /// /// Equivalent to [`HashSet::iter`]. - pub fn iter(&self) -> Iter<'_> { - Iter(self.0.iter(), PhantomData) + pub fn iter(&self) -> EntityHashSetIter<'_> { + EntityHashSetIter(self.0.iter(), PhantomData) } /// Drains elements which are true under the given predicate, @@ -94,10 +94,10 @@ impl DerefMut for EntityHashSet { impl<'a> IntoIterator for &'a EntityHashSet { type Item = &'a Entity; - type IntoIter = Iter<'a>; + type IntoIter = EntityHashSetIter<'a>; fn into_iter(self) -> Self::IntoIter { - Iter((&self.0).into_iter(), PhantomData) + EntityHashSetIter((&self.0).into_iter(), PhantomData) } } @@ -196,16 +196,16 @@ impl FromIterator for EntityHashSet { /// This struct is created by the [`iter`] method on [`EntityHashSet`]. See its documentation for more. /// /// [`iter`]: EntityHashSet::iter -pub struct Iter<'a, S = EntityHash>(hash_set::Iter<'a, Entity>, PhantomData); +pub struct EntityHashSetIter<'a, S = EntityHash>(hash_set::Iter<'a, Entity>, PhantomData); -impl<'a> Iter<'a> { +impl<'a> EntityHashSetIter<'a> { /// Returns the inner [`Iter`](hash_set::Iter). pub fn into_inner(self) -> hash_set::Iter<'a, Entity> { self.0 } } -impl<'a> Deref for Iter<'a> { +impl<'a> Deref for EntityHashSetIter<'a> { type Target = hash_set::Iter<'a, Entity>; fn deref(&self) -> &Self::Target { @@ -213,13 +213,13 @@ impl<'a> Deref for Iter<'a> { } } -impl DerefMut for Iter<'_> { +impl DerefMut for EntityHashSetIter<'_> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } -impl<'a> Iterator for Iter<'a> { +impl<'a> Iterator for EntityHashSetIter<'a> { type Item = &'a Entity; fn next(&mut self) -> Option { @@ -227,39 +227,39 @@ impl<'a> Iterator for Iter<'a> { } } -impl ExactSizeIterator for Iter<'_> {} +impl ExactSizeIterator for EntityHashSetIter<'_> {} -impl FusedIterator for Iter<'_> {} +impl FusedIterator for EntityHashSetIter<'_> {} /// This implementation is somewhat surprising: /// as hash sets make no guarantees about the order of their elements, /// [`DoubleEndedIterator::next_back`] is implemented by simply forwarding to the underlying [`Iter::next`]. -impl DoubleEndedIterator for Iter<'_> { +impl DoubleEndedIterator for EntityHashSetIter<'_> { fn next_back(&mut self) -> Option { self.0.next() } } -impl Clone for Iter<'_> { +impl Clone for EntityHashSetIter<'_> { fn clone(&self) -> Self { Self(self.0.clone(), PhantomData) } } -impl Debug for Iter<'_> { +impl Debug for EntityHashSetIter<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("Iter").field(&self.0).field(&self.1).finish() } } -impl Default for Iter<'_> { +impl Default for EntityHashSetIter<'_> { fn default() -> Self { Self(Default::default(), PhantomData) } } // SAFETY: Iter stems from a correctly behaving `HashSet`. -unsafe impl EntitySetIterator for Iter<'_> {} +unsafe impl EntitySetIterator for EntityHashSetIter<'_> {} /// Owning iterator over the items of an [`EntityHashSet`]. /// diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 946b6821a4e40..614acfd771680 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -57,7 +57,7 @@ mod hash_map; mod hash_set; pub use hash_map::EntityHashMap; -pub use hash_set::EntityHashSet; +pub use hash_set::{EntityHashSet, EntityHashSetIter}; use crate::{ archetype::{ArchetypeId, ArchetypeRow}, diff --git a/crates/bevy_ecs/src/relationship/mod.rs b/crates/bevy_ecs/src/relationship/mod.rs index 84d8bdcd0bf61..42ca65449e907 100644 --- a/crates/bevy_ecs/src/relationship/mod.rs +++ b/crates/bevy_ecs/src/relationship/mod.rs @@ -215,7 +215,10 @@ pub trait RelationshipTarget: Component + Sized { /// Iterates the entities stored in this collection. #[inline] - fn iter(&self) -> impl DoubleEndedIterator { + fn iter( + &self, + ) -> <::Collection as RelationshipSourceCollection>::SourceIter<'_> + { self.collection().iter() } diff --git a/crates/bevy_ecs/src/relationship/relationship_query.rs b/crates/bevy_ecs/src/relationship/relationship_query.rs index f47b6c14caa14..09e71646a3616 100644 --- a/crates/bevy_ecs/src/relationship/relationship_query.rs +++ b/crates/bevy_ecs/src/relationship/relationship_query.rs @@ -7,6 +7,8 @@ use crate::{ use alloc::collections::VecDeque; use smallvec::SmallVec; +use super::RelationshipSourceCollection; + impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { /// If the given `entity` contains the `R` [`Relationship`] component, returns the /// target entity of that relationship. @@ -59,6 +61,8 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { ) -> impl Iterator + 'w where ::ReadOnly: WorldQuery = &'w S>, + <::Collection as RelationshipSourceCollection>::SourceIter<'w>: + DoubleEndedIterator, { self.iter_descendants_depth_first(entity).filter(|entity| { self.get(*entity) @@ -114,6 +118,8 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { ) -> DescendantDepthFirstIter<'w, 's, D, F, S> where D::ReadOnly: WorldQuery = &'w S>, + <::Collection as RelationshipSourceCollection>::SourceIter<'w>: + DoubleEndedIterator, { DescendantDepthFirstIter::new(self, entity) } @@ -195,6 +201,8 @@ impl<'w, 's, D: QueryData, F: QueryFilter, S: RelationshipTarget> DescendantDepthFirstIter<'w, 's, D, F, S> where D::ReadOnly: WorldQuery = &'w S>, + <::Collection as RelationshipSourceCollection>::SourceIter<'w>: + DoubleEndedIterator, { /// Returns a new [`DescendantDepthFirstIter`]. pub fn new(children_query: &'w Query<'w, 's, D, F>, entity: Entity) -> Self { @@ -211,6 +219,8 @@ impl<'w, 's, D: QueryData, F: QueryFilter, S: RelationshipTarget> Iterator for DescendantDepthFirstIter<'w, 's, D, F, S> where D::ReadOnly: WorldQuery = &'w S>, + <::Collection as RelationshipSourceCollection>::SourceIter<'w>: + DoubleEndedIterator, { type Item = Entity; diff --git a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs index 27efd9ed80532..3b4fb8bd157b2 100644 --- a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs +++ b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs @@ -4,6 +4,15 @@ use alloc::vec::Vec; /// The internal [`Entity`] collection used by a [`RelationshipTarget`](crate::relationship::RelationshipTarget) component. /// This is not intended to be modified directly by users, as it could invalidate the correctness of relationships. pub trait RelationshipSourceCollection { + /// The type of iterator returned by the `iter` method. + /// + /// This is an associated type (rather than using a method that returns an opaque return-position impl trait) + /// to ensure that all methods and traits (like [`DoubleEndedIterator`]) of the underlying collection's iterator + /// are available to the user when implemented without unduly restricting the possible collections. + type SourceIter<'a>: Iterator + where + Self: 'a; + /// Returns an instance with the given pre-allocated entity `capacity`. fn with_capacity(capacity: usize) -> Self; @@ -14,7 +23,7 @@ pub trait RelationshipSourceCollection { fn remove(&mut self, entity: Entity); /// Iterates all entities in the collection. - fn iter(&self) -> impl DoubleEndedIterator; + fn iter(&self) -> Self::SourceIter<'_>; /// Returns the current length of the collection. fn len(&self) -> usize; @@ -27,6 +36,8 @@ pub trait RelationshipSourceCollection { } impl RelationshipSourceCollection for Vec { + type SourceIter<'a> = core::iter::Copied>; + fn with_capacity(capacity: usize) -> Self { Vec::with_capacity(capacity) } @@ -41,7 +52,7 @@ impl RelationshipSourceCollection for Vec { } } - fn iter(&self) -> impl DoubleEndedIterator { + fn iter(&self) -> Self::SourceIter<'_> { <[Entity]>::iter(self).copied() } @@ -51,6 +62,8 @@ impl RelationshipSourceCollection for Vec { } impl RelationshipSourceCollection for EntityHashSet { + type SourceIter<'a> = core::iter::Copied>; + fn with_capacity(capacity: usize) -> Self { EntityHashSet::with_capacity(capacity) } @@ -65,7 +78,7 @@ impl RelationshipSourceCollection for EntityHashSet { self.0.remove(&entity); } - fn iter(&self) -> impl DoubleEndedIterator { + fn iter(&self) -> Self::SourceIter<'_> { self.iter().copied() } From 9221e27d788b78db680cdd4bf41d78a72cf0bb10 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 19:28:10 -0800 Subject: [PATCH 06/12] Add a `SourceIter` type alias --- crates/bevy_ecs/src/relationship/mod.rs | 10 ++++++---- .../src/relationship/relationship_query.rs | 14 +++++--------- .../relationship/relationship_source_collection.rs | 2 ++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/bevy_ecs/src/relationship/mod.rs b/crates/bevy_ecs/src/relationship/mod.rs index 42ca65449e907..08dac0ec51dfc 100644 --- a/crates/bevy_ecs/src/relationship/mod.rs +++ b/crates/bevy_ecs/src/relationship/mod.rs @@ -130,6 +130,11 @@ pub trait Relationship: Component + Sized { } } +/// The iterator type for the source entities in a [`RelationshipTarget`] collection, +/// as defined in the [`RelationshipSourceCollection`] trait. +pub type SourceIter<'w, R> = + <::Collection as RelationshipSourceCollection>::SourceIter<'w>; + /// A [`Component`] containing the collection of entities that relate to this [`Entity`] via the associated `Relationship` type. /// See the [`Relationship`] documentation for more information. pub trait RelationshipTarget: Component + Sized { @@ -215,10 +220,7 @@ pub trait RelationshipTarget: Component + Sized { /// Iterates the entities stored in this collection. #[inline] - fn iter( - &self, - ) -> <::Collection as RelationshipSourceCollection>::SourceIter<'_> - { + fn iter(&self) -> SourceIter<'_, Self> { self.collection().iter() } diff --git a/crates/bevy_ecs/src/relationship/relationship_query.rs b/crates/bevy_ecs/src/relationship/relationship_query.rs index 09e71646a3616..f22be81cd8cb8 100644 --- a/crates/bevy_ecs/src/relationship/relationship_query.rs +++ b/crates/bevy_ecs/src/relationship/relationship_query.rs @@ -7,7 +7,7 @@ use crate::{ use alloc::collections::VecDeque; use smallvec::SmallVec; -use super::RelationshipSourceCollection; +use super::SourceIter; impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { /// If the given `entity` contains the `R` [`Relationship`] component, returns the @@ -61,8 +61,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { ) -> impl Iterator + 'w where ::ReadOnly: WorldQuery = &'w S>, - <::Collection as RelationshipSourceCollection>::SourceIter<'w>: - DoubleEndedIterator, + SourceIter<'w, S>: DoubleEndedIterator, { self.iter_descendants_depth_first(entity).filter(|entity| { self.get(*entity) @@ -118,8 +117,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { ) -> DescendantDepthFirstIter<'w, 's, D, F, S> where D::ReadOnly: WorldQuery = &'w S>, - <::Collection as RelationshipSourceCollection>::SourceIter<'w>: - DoubleEndedIterator, + SourceIter<'w, S>: DoubleEndedIterator, { DescendantDepthFirstIter::new(self, entity) } @@ -201,8 +199,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, S: RelationshipTarget> DescendantDepthFirstIter<'w, 's, D, F, S> where D::ReadOnly: WorldQuery = &'w S>, - <::Collection as RelationshipSourceCollection>::SourceIter<'w>: - DoubleEndedIterator, + SourceIter<'w, S>: DoubleEndedIterator, { /// Returns a new [`DescendantDepthFirstIter`]. pub fn new(children_query: &'w Query<'w, 's, D, F>, entity: Entity) -> Self { @@ -219,8 +216,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, S: RelationshipTarget> Iterator for DescendantDepthFirstIter<'w, 's, D, F, S> where D::ReadOnly: WorldQuery = &'w S>, - <::Collection as RelationshipSourceCollection>::SourceIter<'w>: - DoubleEndedIterator, + SourceIter<'w, S>: DoubleEndedIterator, { type Item = Entity; diff --git a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs index 3b4fb8bd157b2..32ba3ce37c99e 100644 --- a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs +++ b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs @@ -9,6 +9,8 @@ pub trait RelationshipSourceCollection { /// This is an associated type (rather than using a method that returns an opaque return-position impl trait) /// to ensure that all methods and traits (like [`DoubleEndedIterator`]) of the underlying collection's iterator /// are available to the user when implemented without unduly restricting the possible collections. + /// + /// The [`SourceIter`](super::SourceIter) type alias can be helpful to reduce confusion when working with this associated type. type SourceIter<'a>: Iterator where Self: 'a; From 4df86f6abfd21089030fd48d9a16f4e3f75366da Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 19:31:57 -0800 Subject: [PATCH 07/12] Impl RelationshipSourceCollection for SmallVec --- .../relationship_source_collection.rs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs index 32ba3ce37c99e..0a53948fd363f 100644 --- a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs +++ b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs @@ -1,5 +1,6 @@ use crate::entity::{Entity, EntityHashSet}; use alloc::vec::Vec; +use smallvec::SmallVec; /// The internal [`Entity`] collection used by a [`RelationshipTarget`](crate::relationship::RelationshipTarget) component. /// This is not intended to be modified directly by users, as it could invalidate the correctness of relationships. @@ -89,6 +90,32 @@ impl RelationshipSourceCollection for EntityHashSet { } } +impl RelationshipSourceCollection for SmallVec<[Entity; N]> { + type SourceIter<'a> = core::iter::Copied>; + + fn with_capacity(capacity: usize) -> Self { + SmallVec::with_capacity(capacity) + } + + fn add(&mut self, entity: Entity) { + SmallVec::push(self, entity); + } + + fn remove(&mut self, entity: Entity) { + if let Some(index) = <[Entity]>::iter(self).position(|e| *e == entity) { + SmallVec::remove(self, index); + } + } + + fn iter(&self) -> Self::SourceIter<'_> { + <[Entity]>::iter(self).copied() + } + + fn len(&self) -> usize { + SmallVec::len(self) + } +} + #[cfg(test)] mod tests { use super::*; @@ -137,4 +164,25 @@ mod tests { let collection = rel_target.collection(); assert_eq!(collection, &EntityHashSet::from([a])); } + + #[test] + fn smallvec_relationship_source_collection() { + #[derive(Component)] + #[relationship(relationship_target = RelTarget)] + struct Rel(Entity); + + #[derive(Component)] + #[relationship_target(relationship = Rel, despawn_descendants)] + struct RelTarget(SmallVec<[Entity; 4]>); + + let mut world = World::new(); + let a = world.spawn_empty().id(); + let b = world.spawn_empty().id(); + + world.entity_mut(a).insert(Rel(b)); + + let rel_target = world.get::(b).unwrap(); + let collection = rel_target.collection(); + assert_eq!(collection, &SmallVec::from_buf([a])); + } } From 1a8564898f1803cae4e99bbf909a40ab824fb8a0 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 19:52:20 -0800 Subject: [PATCH 08/12] Re-export hash_map + hash_set modules rather than renaming --- benches/benches/bevy_ecs/world/entity_hash.rs | 2 +- .../bevy_core_pipeline/src/oit/resolve/mod.rs | 2 +- crates/bevy_ecs/src/entity/hash_map.rs | 4 +++ crates/bevy_ecs/src/entity/hash_set.rs | 4 +++ crates/bevy_ecs/src/entity/map_entities.rs | 6 ++-- crates/bevy_ecs/src/entity/mod.rs | 7 ++--- crates/bevy_ecs/src/entity/visit_entities.rs | 2 +- crates/bevy_ecs/src/observer/mod.rs | 2 +- .../relationship_source_collection.rs | 4 +-- crates/bevy_ecs/src/world/deferred_world.rs | 10 +++---- crates/bevy_ecs/src/world/entity_fetch.rs | 2 +- crates/bevy_ecs/src/world/mod.rs | 30 +++++++++---------- crates/bevy_gilrs/src/lib.rs | 2 +- crates/bevy_gltf/src/loader.rs | 2 +- .../src/directional_navigation.rs | 2 +- crates/bevy_pbr/src/cluster/mod.rs | 2 +- crates/bevy_pbr/src/components.rs | 2 +- crates/bevy_pbr/src/light/mod.rs | 2 +- .../bevy_pbr/src/meshlet/instance_manager.rs | 2 +- .../bevy_pbr/src/meshlet/resource_manager.rs | 2 +- crates/bevy_pbr/src/render/light.rs | 2 +- .../src/batching/gpu_preprocessing.rs | 2 +- crates/bevy_render/src/primitives/mod.rs | 2 +- crates/bevy_render/src/view/visibility/mod.rs | 2 +- .../bevy_render/src/view/visibility/range.rs | 2 +- crates/bevy_render/src/view/window/mod.rs | 2 +- .../bevy_render/src/view/window/screenshot.rs | 2 +- crates/bevy_scene/src/dynamic_scene.rs | 4 +-- crates/bevy_scene/src/scene.rs | 2 +- crates/bevy_scene/src/scene_spawner.rs | 2 +- crates/bevy_scene/src/serde.rs | 2 +- crates/bevy_text/src/text2d.rs | 2 +- crates/bevy_ui/src/layout/mod.rs | 2 +- crates/bevy_ui/src/layout/ui_surface.rs | 2 +- crates/bevy_ui/src/render/mod.rs | 2 +- crates/bevy_ui/src/widget/text.rs | 2 +- crates/bevy_winit/src/accessibility.rs | 2 +- crates/bevy_winit/src/winit_windows.rs | 2 +- .../tools/scene_viewer/animation_plugin.rs | 4 ++- 39 files changed, 70 insertions(+), 63 deletions(-) diff --git a/benches/benches/bevy_ecs/world/entity_hash.rs b/benches/benches/bevy_ecs/world/entity_hash.rs index d4ba9b659820f..5e92443bf1dbb 100644 --- a/benches/benches/bevy_ecs/world/entity_hash.rs +++ b/benches/benches/bevy_ecs/world/entity_hash.rs @@ -1,4 +1,4 @@ -use bevy_ecs::entity::{Entity, EntityHashSet}; +use bevy_ecs::entity::{hash_set::EntityHashSet, Entity}; use criterion::{BenchmarkId, Criterion, Throughput}; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha8Rng; diff --git a/crates/bevy_core_pipeline/src/oit/resolve/mod.rs b/crates/bevy_core_pipeline/src/oit/resolve/mod.rs index a0e97e0770b17..646395381a3a6 100644 --- a/crates/bevy_core_pipeline/src/oit/resolve/mod.rs +++ b/crates/bevy_core_pipeline/src/oit/resolve/mod.rs @@ -6,7 +6,7 @@ use bevy_app::Plugin; use bevy_asset::{load_internal_asset, Handle}; use bevy_derive::Deref; use bevy_ecs::{ - entity::{EntityHashMap, EntityHashSet}, + entity::{hash_set::EntityHashSet, hash_map::EntityHashMap}, prelude::*, }; use bevy_image::BevyDefault as _; diff --git a/crates/bevy_ecs/src/entity/hash_map.rs b/crates/bevy_ecs/src/entity/hash_map.rs index 20ec6767baa46..9246b236904c4 100644 --- a/crates/bevy_ecs/src/entity/hash_map.rs +++ b/crates/bevy_ecs/src/entity/hash_map.rs @@ -1,3 +1,7 @@ +//! Contains the [`EntityHashMap`] type, a [`HashMap`] pre-configured to use [`EntityHash`] hashing. +//! +//! This module is a lightweight wrapper around [`hashbrown`](bevy_utils::hashbrown)'s [`HashMap`] that is more performant for [`Entity`] keys. + use core::{ fmt::{self, Debug, Formatter}, iter::FusedIterator, diff --git a/crates/bevy_ecs/src/entity/hash_set.rs b/crates/bevy_ecs/src/entity/hash_set.rs index 0950380c26633..f02bf0d7fdc50 100644 --- a/crates/bevy_ecs/src/entity/hash_set.rs +++ b/crates/bevy_ecs/src/entity/hash_set.rs @@ -1,3 +1,7 @@ +//! Contains the [`EntityHashSet`] type, a [`HashSet`] pre-configured to use [`EntityHash`] hashing. +//! +//! This module is a lightweight wrapper around [`hashbrown`](bevy_utils::hashbrown)'s [`HashSet`] that is more performant for [`Entity`] keys. + use core::{ fmt::{self, Debug, Formatter}, iter::FusedIterator, diff --git a/crates/bevy_ecs/src/entity/map_entities.rs b/crates/bevy_ecs/src/entity/map_entities.rs index 5b0de2359d6b8..688b523380bf0 100644 --- a/crates/bevy_ecs/src/entity/map_entities.rs +++ b/crates/bevy_ecs/src/entity/map_entities.rs @@ -4,7 +4,7 @@ use crate::{ world::World, }; -use super::{EntityHashMap, VisitEntitiesMut}; +use super::{hash_map::EntityHashMap, VisitEntitiesMut}; /// Operation to map all contained [`Entity`] fields in a type to new values. /// @@ -71,7 +71,7 @@ impl MapEntities for T { /// /// ``` /// # use bevy_ecs::entity::{Entity, EntityMapper}; -/// # use bevy_ecs::entity::EntityHashMap; +/// # use bevy_ecs::entity::hash_map::EntityHashMap; /// # /// pub struct SimpleEntityMapper { /// map: EntityHashMap, @@ -194,7 +194,7 @@ impl<'m> SceneEntityMapper<'m> { #[cfg(test)] mod tests { use crate::{ - entity::{Entity, EntityHashMap, EntityMapper, SceneEntityMapper}, + entity::{hash_map::EntityHashMap, Entity, EntityMapper, SceneEntityMapper}, world::World, }; diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 614acfd771680..50d0215b90cbd 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -53,11 +53,8 @@ pub use visit_entities::*; mod hash; pub use hash::*; -mod hash_map; -mod hash_set; - -pub use hash_map::EntityHashMap; -pub use hash_set::{EntityHashSet, EntityHashSetIter}; +pub mod hash_map; +pub mod hash_set; use crate::{ archetype::{ArchetypeId, ArchetypeRow}, diff --git a/crates/bevy_ecs/src/entity/visit_entities.rs b/crates/bevy_ecs/src/entity/visit_entities.rs index 0896d7208100a..0f957ca265a7a 100644 --- a/crates/bevy_ecs/src/entity/visit_entities.rs +++ b/crates/bevy_ecs/src/entity/visit_entities.rs @@ -58,7 +58,7 @@ impl VisitEntitiesMut for Entity { mod tests { use crate::{ self as bevy_ecs, - entity::{EntityHashMap, MapEntities, SceneEntityMapper}, + entity::{hash_map::EntityHashMap, MapEntities, SceneEntityMapper}, world::World, }; use alloc::{string::String, vec, vec::Vec}; diff --git a/crates/bevy_ecs/src/observer/mod.rs b/crates/bevy_ecs/src/observer/mod.rs index 9f147dd91b829..c07aa6606d60a 100644 --- a/crates/bevy_ecs/src/observer/mod.rs +++ b/crates/bevy_ecs/src/observer/mod.rs @@ -9,7 +9,7 @@ pub use runner::*; use crate::{ archetype::ArchetypeFlags, component::ComponentId, - entity::EntityHashMap, + entity::hash_map::EntityHashMap, prelude::*, system::IntoObserverSystem, world::{DeferredWorld, *}, diff --git a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs index 0a53948fd363f..f0486acda9a1a 100644 --- a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs +++ b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs @@ -1,4 +1,4 @@ -use crate::entity::{Entity, EntityHashSet}; +use crate::entity::{hash_set::EntityHashSet, Entity}; use alloc::vec::Vec; use smallvec::SmallVec; @@ -65,7 +65,7 @@ impl RelationshipSourceCollection for Vec { } impl RelationshipSourceCollection for EntityHashSet { - type SourceIter<'a> = core::iter::Copied>; + type SourceIter<'a> = core::iter::Copied>; fn with_capacity(capacity: usize) -> Self { EntityHashSet::with_capacity(capacity) diff --git a/crates/bevy_ecs/src/world/deferred_world.rs b/crates/bevy_ecs/src/world/deferred_world.rs index 3564b8eae1002..9a6674afe56db 100644 --- a/crates/bevy_ecs/src/world/deferred_world.rs +++ b/crates/bevy_ecs/src/world/deferred_world.rs @@ -189,8 +189,8 @@ impl<'w> DeferredWorld<'w> { /// For examples, see [`DeferredWorld::entity_mut`]. /// /// [`EntityMut`]: crate::world::EntityMut - /// [`&EntityHashSet`]: crate::entity::EntityHashSet - /// [`EntityHashMap`]: crate::entity::EntityHashMap + /// [`&EntityHashSet`]: crate::entity::hash_set::EntityHashSet + /// [`EntityHashMap`]: crate::entity::hash_map::EntityHashMap /// [`Vec`]: alloc::vec::Vec #[inline] pub fn get_entity_mut( @@ -298,7 +298,7 @@ impl<'w> DeferredWorld<'w> { /// ## [`&EntityHashSet`] /// /// ``` - /// # use bevy_ecs::{prelude::*, entity::EntityHashSet, world::DeferredWorld}; + /// # use bevy_ecs::{prelude::*, entity::hash_set::EntityHashSet, world::DeferredWorld}; /// #[derive(Component)] /// struct Position { /// x: f32, @@ -321,8 +321,8 @@ impl<'w> DeferredWorld<'w> { /// ``` /// /// [`EntityMut`]: crate::world::EntityMut - /// [`&EntityHashSet`]: crate::entity::EntityHashSet - /// [`EntityHashMap`]: crate::entity::EntityHashMap + /// [`&EntityHashSet`]: crate::entity::hash_set::EntityHashSet + /// [`EntityHashMap`]: crate::entity::hash_map::EntityHashMap /// [`Vec`]: alloc::vec::Vec #[inline] pub fn entity_mut(&mut self, entities: F) -> F::DeferredMut<'_> { diff --git a/crates/bevy_ecs/src/world/entity_fetch.rs b/crates/bevy_ecs/src/world/entity_fetch.rs index 05a5c51aff67e..466dcc31d01e2 100644 --- a/crates/bevy_ecs/src/world/entity_fetch.rs +++ b/crates/bevy_ecs/src/world/entity_fetch.rs @@ -2,7 +2,7 @@ use alloc::vec::Vec; use core::mem::MaybeUninit; use crate::{ - entity::{Entity, EntityHashMap, EntityHashSet}, + entity::{hash_map::EntityHashMap, hash_set::EntityHashSet, Entity}, world::{ error::EntityFetchError, unsafe_world_cell::UnsafeWorldCell, EntityMut, EntityRef, EntityWorldMut, diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 1bac1df44dcd7..f10fe6c116e09 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -654,10 +654,10 @@ impl World { /// } /// ``` /// - /// ## [`EntityHashSet`](crate::entity::EntityHashMap) + /// ## [`EntityHashSet`](crate::entity::hash_map::EntityHashMap) /// /// ``` - /// # use bevy_ecs::{prelude::*, entity::EntityHashSet}; + /// # use bevy_ecs::{prelude::*, entity::hash_set::EntityHashSet}; /// #[derive(Component)] /// struct Position { /// x: f32, @@ -675,7 +675,7 @@ impl World { /// } /// ``` /// - /// [`EntityHashSet`]: crate::entity::EntityHashSet + /// [`EntityHashSet`]: crate::entity::hash_set::EntityHashSet #[inline] #[track_caller] pub fn entity(&self, entities: F) -> F::Ref<'_> { @@ -706,8 +706,8 @@ impl World { /// such as adding or removing components, or despawning the entity. /// - Pass a slice of [`Entity`]s to receive a [`Vec`]. /// - Pass an array of [`Entity`]s to receive an equally-sized array of [`EntityMut`]s. - /// - Pass a reference to a [`EntityHashSet`](crate::entity::EntityHashMap) to receive an - /// [`EntityHashMap`](crate::entity::EntityHashMap). + /// - Pass a reference to a [`EntityHashSet`](crate::entity::hash_map::EntityHashMap) to receive an + /// [`EntityHashMap`](crate::entity::hash_map::EntityHashMap). /// /// In order to perform structural changes on the returned entity reference, /// such as adding or removing components, or despawning the entity, only a @@ -788,10 +788,10 @@ impl World { /// } /// ``` /// - /// ## [`EntityHashSet`](crate::entity::EntityHashMap) + /// ## [`EntityHashSet`](crate::entity::hash_map::EntityHashMap) /// /// ``` - /// # use bevy_ecs::{prelude::*, entity::EntityHashSet}; + /// # use bevy_ecs::{prelude::*, entity::hash_set::EntityHashSet}; /// #[derive(Component)] /// struct Position { /// x: f32, @@ -811,7 +811,7 @@ impl World { /// } /// ``` /// - /// [`EntityHashSet`]: crate::entity::EntityHashSet + /// [`EntityHashSet`]: crate::entity::hash_set::EntityHashSet #[inline] #[track_caller] pub fn entity_mut(&mut self, entities: F) -> F::Mut<'_> { @@ -860,8 +860,8 @@ impl World { /// - Pass an [`Entity`] to receive a single [`EntityRef`]. /// - Pass a slice of [`Entity`]s to receive a [`Vec`]. /// - Pass an array of [`Entity`]s to receive an equally-sized array of [`EntityRef`]s. - /// - Pass a reference to a [`EntityHashSet`](crate::entity::EntityHashMap) to receive an - /// [`EntityHashMap`](crate::entity::EntityHashMap). + /// - Pass a reference to a [`EntityHashSet`](crate::entity::hash_map::EntityHashMap) to receive an + /// [`EntityHashMap`](crate::entity::hash_map::EntityHashMap). /// /// # Errors /// @@ -872,7 +872,7 @@ impl World { /// /// For examples, see [`World::entity`]. /// - /// [`EntityHashSet`]: crate::entity::EntityHashSet + /// [`EntityHashSet`]: crate::entity::hash_set::EntityHashSet #[inline] pub fn get_entity(&self, entities: F) -> Result, Entity> { let cell = self.as_unsafe_world_cell_readonly(); @@ -891,8 +891,8 @@ impl World { /// such as adding or removing components, or despawning the entity. /// - Pass a slice of [`Entity`]s to receive a [`Vec`]. /// - Pass an array of [`Entity`]s to receive an equally-sized array of [`EntityMut`]s. - /// - Pass a reference to a [`EntityHashSet`](crate::entity::EntityHashMap) to receive an - /// [`EntityHashMap`](crate::entity::EntityHashMap). + /// - Pass a reference to a [`EntityHashSet`](crate::entity::hash_map::EntityHashMap) to receive an + /// [`EntityHashMap`](crate::entity::hash_map::EntityHashMap). /// /// In order to perform structural changes on the returned entity reference, /// such as adding or removing components, or despawning the entity, only a @@ -910,7 +910,7 @@ impl World { /// /// For examples, see [`World::entity_mut`]. /// - /// [`EntityHashSet`]: crate::entity::EntityHashSet + /// [`EntityHashSet`]: crate::entity::hash_set::EntityHashSet #[inline] pub fn get_entity_mut( &mut self, @@ -3684,7 +3684,7 @@ mod tests { use crate::{ change_detection::DetectChangesMut, component::{ComponentDescriptor, ComponentInfo, StorageType}, - entity::EntityHashSet, + entity::hash_set::EntityHashSet, ptr::OwningPtr, system::Resource, world::error::EntityFetchError, diff --git a/crates/bevy_gilrs/src/lib.rs b/crates/bevy_gilrs/src/lib.rs index b8d83adbf3592..404b6894ac658 100644 --- a/crates/bevy_gilrs/src/lib.rs +++ b/crates/bevy_gilrs/src/lib.rs @@ -15,7 +15,7 @@ mod gilrs_system; mod rumble; use bevy_app::{App, Plugin, PostUpdate, PreStartup, PreUpdate}; -use bevy_ecs::entity::EntityHashMap; +use bevy_ecs::entity::hash_map::EntityHashMap; use bevy_ecs::prelude::*; use bevy_input::InputSystem; use bevy_utils::{synccell::SyncCell, HashMap}; diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 5b9810d184c84..f4f19eefe3fa2 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -10,7 +10,7 @@ use bevy_asset::{ use bevy_color::{Color, LinearRgba}; use bevy_core_pipeline::prelude::Camera3d; use bevy_ecs::{ - entity::{Entity, EntityHashMap}, + entity::{Entity, hash_map::EntityHashMap}, hierarchy::ChildSpawner, name::Name, world::World, diff --git a/crates/bevy_input_focus/src/directional_navigation.rs b/crates/bevy_input_focus/src/directional_navigation.rs index fd64cd41a732c..c6428c444b5b2 100644 --- a/crates/bevy_input_focus/src/directional_navigation.rs +++ b/crates/bevy_input_focus/src/directional_navigation.rs @@ -17,7 +17,7 @@ use bevy_app::prelude::*; use bevy_ecs::{ - entity::{EntityHashMap, EntityHashSet}, + entity::{hash_map::EntityHashMap, hash_set::EntityHashSet}, prelude::*, system::SystemParam, }; diff --git a/crates/bevy_pbr/src/cluster/mod.rs b/crates/bevy_pbr/src/cluster/mod.rs index eb7834871ba8b..9368fed513dac 100644 --- a/crates/bevy_pbr/src/cluster/mod.rs +++ b/crates/bevy_pbr/src/cluster/mod.rs @@ -5,7 +5,7 @@ use core::num::NonZero; use bevy_core_pipeline::core_3d::Camera3d; use bevy_ecs::{ component::Component, - entity::{Entity, EntityHashMap}, + entity::{Entity, hash_map::EntityHashMap}, query::{With, Without}, reflect::ReflectComponent, system::{Commands, Query, Res, Resource}, diff --git a/crates/bevy_pbr/src/components.rs b/crates/bevy_pbr/src/components.rs index 189862cc55e9a..d8ad173cb96f9 100644 --- a/crates/bevy_pbr/src/components.rs +++ b/crates/bevy_pbr/src/components.rs @@ -1,6 +1,6 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::component::Component; -use bevy_ecs::entity::{Entity, EntityHashMap}; +use bevy_ecs::entity::{Entity, hash_map::EntityHashMap}; use bevy_ecs::reflect::ReflectComponent; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::sync_world::MainEntity; diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index 5525029ef4250..00d60993c4da4 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -1,7 +1,7 @@ use core::ops::DerefMut; use bevy_ecs::{ - entity::{EntityHashMap, EntityHashSet}, + entity::{hash_map::EntityHashMap, hash_set::EntityHashSet}, prelude::*, }; use bevy_math::{ops, Mat4, Vec3A, Vec4}; diff --git a/crates/bevy_pbr/src/meshlet/instance_manager.rs b/crates/bevy_pbr/src/meshlet/instance_manager.rs index 7a78abe482104..c112d89b318c8 100644 --- a/crates/bevy_pbr/src/meshlet/instance_manager.rs +++ b/crates/bevy_pbr/src/meshlet/instance_manager.rs @@ -5,7 +5,7 @@ use crate::{ }; use bevy_asset::{AssetEvent, AssetServer, Assets, UntypedAssetId}; use bevy_ecs::{ - entity::{Entities, Entity, EntityHashMap}, + entity::{Entities, Entity, hash_map::EntityHashMap}, event::EventReader, query::Has, system::{Local, Query, Res, ResMut, Resource, SystemState}, diff --git a/crates/bevy_pbr/src/meshlet/resource_manager.rs b/crates/bevy_pbr/src/meshlet/resource_manager.rs index c918990869cec..9f9a42d5bcae7 100644 --- a/crates/bevy_pbr/src/meshlet/resource_manager.rs +++ b/crates/bevy_pbr/src/meshlet/resource_manager.rs @@ -7,7 +7,7 @@ use bevy_core_pipeline::{ }; use bevy_ecs::{ component::Component, - entity::{Entity, EntityHashMap}, + entity::{Entity, hash_map::EntityHashMap}, query::AnyOf, system::{Commands, Query, Res, ResMut, Resource}, }; diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 4a1187400e5fe..63fca28aed909 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -6,7 +6,7 @@ use bevy_color::ColorToComponents; use bevy_core_pipeline::core_3d::{Camera3d, CORE_3D_DEPTH_FORMAT}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ - entity::{EntityHashMap, EntityHashSet}, + entity::{hash_map::EntityHashMap, hash_set::EntityHashSet}, prelude::*, system::lifetimeless::Read, }; diff --git a/crates/bevy_render/src/batching/gpu_preprocessing.rs b/crates/bevy_render/src/batching/gpu_preprocessing.rs index 2e893616f9294..d9cfbbf334cb3 100644 --- a/crates/bevy_render/src/batching/gpu_preprocessing.rs +++ b/crates/bevy_render/src/batching/gpu_preprocessing.rs @@ -4,7 +4,7 @@ use core::any::TypeId; use bevy_app::{App, Plugin}; use bevy_ecs::{ - entity::{Entity, EntityHashMap}, + entity::{hash_map::EntityHashMap, Entity}, query::{Has, With}, schedule::IntoSystemConfigs as _, system::{Query, Res, ResMut, Resource, StaticSystemParam}, diff --git a/crates/bevy_render/src/primitives/mod.rs b/crates/bevy_render/src/primitives/mod.rs index 48c0652fef3b9..9123e95b5e946 100644 --- a/crates/bevy_render/src/primitives/mod.rs +++ b/crates/bevy_render/src/primitives/mod.rs @@ -1,6 +1,6 @@ use core::borrow::Borrow; -use bevy_ecs::{component::Component, entity::EntityHashMap, reflect::ReflectComponent}; +use bevy_ecs::{component::Component, entity::hash_map::EntityHashMap, reflect::ReflectComponent}; use bevy_math::{Affine3A, Mat3A, Mat4, Vec3, Vec3A, Vec4, Vec4Swizzles}; use bevy_reflect::prelude::*; diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index d0c84bd70ad19..0e329deefdf8c 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -4,7 +4,7 @@ mod render_layers; use core::any::TypeId; use bevy_ecs::component::ComponentId; -use bevy_ecs::entity::EntityHashSet; +use bevy_ecs::entity::hash_set::EntityHashSet; use bevy_ecs::world::DeferredWorld; use derive_more::derive::{Deref, DerefMut}; pub use range::*; diff --git a/crates/bevy_render/src/view/visibility/range.rs b/crates/bevy_render/src/view/visibility/range.rs index d62a9ffb69c5e..e6f6484d05584 100644 --- a/crates/bevy_render/src/view/visibility/range.rs +++ b/crates/bevy_render/src/view/visibility/range.rs @@ -9,7 +9,7 @@ use core::{ use bevy_app::{App, Plugin, PostUpdate}; use bevy_ecs::{ component::Component, - entity::{Entity, EntityHashMap}, + entity::{hash_map::EntityHashMap, Entity}, query::{Changed, With}, reflect::ReflectComponent, removal_detection::RemovedComponents, diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index e6c257e4a6510..87d5654e7b1a6 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -4,7 +4,7 @@ use crate::{ Extract, ExtractSchedule, Render, RenderApp, RenderSet, WgpuWrapper, }; use bevy_app::{App, Plugin}; -use bevy_ecs::{entity::EntityHashMap, prelude::*}; +use bevy_ecs::{entity::hash_map::EntityHashMap, prelude::*}; use bevy_utils::{default, HashSet}; use bevy_window::{ CompositeAlphaMode, PresentMode, PrimaryWindow, RawHandleWrapper, Window, WindowClosing, diff --git a/crates/bevy_render/src/view/window/screenshot.rs b/crates/bevy_render/src/view/window/screenshot.rs index 81adc30486cd0..574153e694e40 100644 --- a/crates/bevy_render/src/view/window/screenshot.rs +++ b/crates/bevy_render/src/view/window/screenshot.rs @@ -20,7 +20,7 @@ use bevy_app::{First, Plugin, Update}; use bevy_asset::{load_internal_asset, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ - entity::EntityHashMap, event::event_update_system, prelude::*, system::SystemState, + entity::hash_map::EntityHashMap, event::event_update_system, prelude::*, system::SystemState, }; use bevy_image::{Image, TextureFormatPixelInfo}; use bevy_reflect::Reflect; diff --git a/crates/bevy_scene/src/dynamic_scene.rs b/crates/bevy_scene/src/dynamic_scene.rs index f8adb6d0704f1..4936735c6994a 100644 --- a/crates/bevy_scene/src/dynamic_scene.rs +++ b/crates/bevy_scene/src/dynamic_scene.rs @@ -2,7 +2,7 @@ use crate::{ron, DynamicSceneBuilder, Scene, SceneSpawnError}; use bevy_asset::Asset; use bevy_ecs::reflect::ReflectResource; use bevy_ecs::{ - entity::{Entity, EntityHashMap, SceneEntityMapper}, + entity::{Entity, hash_map::EntityHashMap, SceneEntityMapper}, reflect::{AppTypeRegistry, ReflectComponent, ReflectMapEntities}, world::World, }; @@ -200,7 +200,7 @@ mod tests { use bevy_ecs::{ component::Component, entity::{ - Entity, EntityHashMap, EntityMapper, MapEntities, VisitEntities, VisitEntitiesMut, + Entity, hash_map::EntityHashMap, EntityMapper, MapEntities, VisitEntities, VisitEntitiesMut, }, hierarchy::Parent, reflect::{AppTypeRegistry, ReflectComponent, ReflectMapEntities, ReflectResource}, diff --git a/crates/bevy_scene/src/scene.rs b/crates/bevy_scene/src/scene.rs index aba8a55d46796..d4baddce814b2 100644 --- a/crates/bevy_scene/src/scene.rs +++ b/crates/bevy_scene/src/scene.rs @@ -1,7 +1,7 @@ use crate::{DynamicScene, SceneSpawnError}; use bevy_asset::Asset; use bevy_ecs::{ - entity::{Entity, EntityHashMap, SceneEntityMapper}, + entity::{Entity, hash_map::EntityHashMap, SceneEntityMapper}, reflect::{AppTypeRegistry, ReflectComponent, ReflectMapEntities, ReflectResource}, world::World, }; diff --git a/crates/bevy_scene/src/scene_spawner.rs b/crates/bevy_scene/src/scene_spawner.rs index 9d3c99996d15a..1a9752f3dea35 100644 --- a/crates/bevy_scene/src/scene_spawner.rs +++ b/crates/bevy_scene/src/scene_spawner.rs @@ -1,7 +1,7 @@ use crate::{DynamicScene, Scene}; use bevy_asset::{AssetEvent, AssetId, Assets, Handle}; use bevy_ecs::{ - entity::{Entity, EntityHashMap}, + entity::{Entity, hash_map::EntityHashMap}, event::{Event, EventCursor, Events}, hierarchy::Parent, reflect::AppTypeRegistry, diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index a59fa67692ca1..3b9ccb8a2f865 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -515,7 +515,7 @@ mod tests { DynamicScene, DynamicSceneBuilder, }; use bevy_ecs::{ - entity::{Entity, EntityHashMap, VisitEntities, VisitEntitiesMut}, + entity::{Entity, hash_map::EntityHashMap, VisitEntities, VisitEntitiesMut}, prelude::{Component, ReflectComponent, ReflectResource, Resource, World}, query::{With, Without}, reflect::{AppTypeRegistry, ReflectMapEntities}, diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 062532e377f88..8e9fd43d19303 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -7,7 +7,7 @@ use crate::{ use bevy_asset::Assets; use bevy_color::LinearRgba; use bevy_derive::{Deref, DerefMut}; -use bevy_ecs::entity::EntityHashSet; +use bevy_ecs::entity::hash_set::EntityHashSet; use bevy_ecs::{ change_detection::{DetectChanges, Ref}, component::{require, Component}, diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index f80d86cb4cc14..6d017592c7fe1 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -4,7 +4,7 @@ use crate::{ OverflowAxis, ScrollPosition, UiScale, UiTargetCamera, Val, }; use bevy_ecs::{ - entity::{EntityHashMap, EntityHashSet}, + entity::{hash_map::EntityHashMap, hash_set::EntityHashSet}, prelude::*, system::SystemParam, }; diff --git a/crates/bevy_ui/src/layout/ui_surface.rs b/crates/bevy_ui/src/layout/ui_surface.rs index b57d1041a30d7..9dac92f597bbf 100644 --- a/crates/bevy_ui/src/layout/ui_surface.rs +++ b/crates/bevy_ui/src/layout/ui_surface.rs @@ -3,7 +3,7 @@ use core::fmt; use taffy::TaffyTree; use bevy_ecs::{ - entity::{Entity, EntityHashMap}, + entity::{hash_map::EntityHashMap, Entity}, prelude::Resource, }; use bevy_math::{UVec2, Vec2}; diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index fded21965e1ff..99927619719dc 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -18,7 +18,7 @@ use bevy_color::{Alpha, ColorToComponents, LinearRgba}; use bevy_core_pipeline::core_2d::graph::{Core2d, Node2d}; use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d}; use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d}; -use bevy_ecs::entity::EntityHashMap; +use bevy_ecs::entity::hash_map::EntityHashMap; use bevy_ecs::prelude::*; use bevy_image::prelude::*; use bevy_math::{FloatOrd, Mat4, Rect, UVec4, Vec2, Vec3, Vec3Swizzles, Vec4Swizzles}; diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 237d7abfb2467..1f0dcc654157b 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -7,7 +7,7 @@ use bevy_color::Color; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ change_detection::DetectChanges, - entity::{Entity, EntityHashMap}, + entity::{hash_map::EntityHashMap, Entity}, prelude::{require, Component}, query::With, reflect::ReflectComponent, diff --git a/crates/bevy_winit/src/accessibility.rs b/crates/bevy_winit/src/accessibility.rs index 939916f6eb401..c6955bd21dddc 100644 --- a/crates/bevy_winit/src/accessibility.rs +++ b/crates/bevy_winit/src/accessibility.rs @@ -15,7 +15,7 @@ use bevy_a11y::{ }; use bevy_app::{App, Plugin, PostUpdate}; use bevy_derive::{Deref, DerefMut}; -use bevy_ecs::{entity::EntityHashMap, prelude::*}; +use bevy_ecs::{entity::hash_map::EntityHashMap, prelude::*}; use bevy_window::{PrimaryWindow, Window, WindowClosed}; /// Maps window entities to their `AccessKit` [`Adapter`]s. diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index f7b948a6bd530..9f7896d4c7e4e 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -1,7 +1,7 @@ use bevy_a11y::AccessibilityRequested; use bevy_ecs::entity::Entity; -use bevy_ecs::entity::EntityHashMap; +use bevy_ecs::entity::hash_map::EntityHashMap; use bevy_utils::HashMap; use bevy_window::{ CursorGrabMode, MonitorSelection, Window, WindowMode, WindowPosition, WindowResolution, diff --git a/examples/tools/scene_viewer/animation_plugin.rs b/examples/tools/scene_viewer/animation_plugin.rs index 7438392739a0d..298a10199f8bb 100644 --- a/examples/tools/scene_viewer/animation_plugin.rs +++ b/examples/tools/scene_viewer/animation_plugin.rs @@ -1,7 +1,9 @@ //! Control animations of entities in the loaded scene. use std::collections::HashMap; -use bevy::{animation::AnimationTarget, ecs::entity::EntityHashMap, gltf::Gltf, prelude::*}; +use bevy::{ + animation::AnimationTarget, ecs::entity::hash_map::EntityHashMap, gltf::Gltf, prelude::*, +}; use crate::scene_viewer_plugin::SceneHandle; From 6e22d27a0f3ac61d481bdae81e30450132048270 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 20:13:59 -0800 Subject: [PATCH 09/12] `cargo fmt` --- crates/bevy_core_pipeline/src/oit/resolve/mod.rs | 2 +- crates/bevy_gltf/src/loader.rs | 2 +- crates/bevy_pbr/src/cluster/mod.rs | 2 +- crates/bevy_pbr/src/components.rs | 2 +- crates/bevy_pbr/src/meshlet/instance_manager.rs | 2 +- crates/bevy_pbr/src/meshlet/resource_manager.rs | 2 +- crates/bevy_scene/src/dynamic_scene.rs | 5 +++-- crates/bevy_scene/src/scene.rs | 2 +- crates/bevy_scene/src/scene_spawner.rs | 2 +- crates/bevy_scene/src/serde.rs | 2 +- 10 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/bevy_core_pipeline/src/oit/resolve/mod.rs b/crates/bevy_core_pipeline/src/oit/resolve/mod.rs index 646395381a3a6..690f95fda33db 100644 --- a/crates/bevy_core_pipeline/src/oit/resolve/mod.rs +++ b/crates/bevy_core_pipeline/src/oit/resolve/mod.rs @@ -6,7 +6,7 @@ use bevy_app::Plugin; use bevy_asset::{load_internal_asset, Handle}; use bevy_derive::Deref; use bevy_ecs::{ - entity::{hash_set::EntityHashSet, hash_map::EntityHashMap}, + entity::{hash_map::EntityHashMap, hash_set::EntityHashSet}, prelude::*, }; use bevy_image::BevyDefault as _; diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index f4f19eefe3fa2..487515a6d90e9 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -10,7 +10,7 @@ use bevy_asset::{ use bevy_color::{Color, LinearRgba}; use bevy_core_pipeline::prelude::Camera3d; use bevy_ecs::{ - entity::{Entity, hash_map::EntityHashMap}, + entity::{hash_map::EntityHashMap, Entity}, hierarchy::ChildSpawner, name::Name, world::World, diff --git a/crates/bevy_pbr/src/cluster/mod.rs b/crates/bevy_pbr/src/cluster/mod.rs index 9368fed513dac..6a2baa554ad69 100644 --- a/crates/bevy_pbr/src/cluster/mod.rs +++ b/crates/bevy_pbr/src/cluster/mod.rs @@ -5,7 +5,7 @@ use core::num::NonZero; use bevy_core_pipeline::core_3d::Camera3d; use bevy_ecs::{ component::Component, - entity::{Entity, hash_map::EntityHashMap}, + entity::{hash_map::EntityHashMap, Entity}, query::{With, Without}, reflect::ReflectComponent, system::{Commands, Query, Res, Resource}, diff --git a/crates/bevy_pbr/src/components.rs b/crates/bevy_pbr/src/components.rs index d8ad173cb96f9..d5418910eb37e 100644 --- a/crates/bevy_pbr/src/components.rs +++ b/crates/bevy_pbr/src/components.rs @@ -1,6 +1,6 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::component::Component; -use bevy_ecs::entity::{Entity, hash_map::EntityHashMap}; +use bevy_ecs::entity::{hash_map::EntityHashMap, Entity}; use bevy_ecs::reflect::ReflectComponent; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::sync_world::MainEntity; diff --git a/crates/bevy_pbr/src/meshlet/instance_manager.rs b/crates/bevy_pbr/src/meshlet/instance_manager.rs index c112d89b318c8..e87f100f8a139 100644 --- a/crates/bevy_pbr/src/meshlet/instance_manager.rs +++ b/crates/bevy_pbr/src/meshlet/instance_manager.rs @@ -5,7 +5,7 @@ use crate::{ }; use bevy_asset::{AssetEvent, AssetServer, Assets, UntypedAssetId}; use bevy_ecs::{ - entity::{Entities, Entity, hash_map::EntityHashMap}, + entity::{hash_map::EntityHashMap, Entities, Entity}, event::EventReader, query::Has, system::{Local, Query, Res, ResMut, Resource, SystemState}, diff --git a/crates/bevy_pbr/src/meshlet/resource_manager.rs b/crates/bevy_pbr/src/meshlet/resource_manager.rs index 9f9a42d5bcae7..05c7e52249594 100644 --- a/crates/bevy_pbr/src/meshlet/resource_manager.rs +++ b/crates/bevy_pbr/src/meshlet/resource_manager.rs @@ -7,7 +7,7 @@ use bevy_core_pipeline::{ }; use bevy_ecs::{ component::Component, - entity::{Entity, hash_map::EntityHashMap}, + entity::{hash_map::EntityHashMap, Entity}, query::AnyOf, system::{Commands, Query, Res, ResMut, Resource}, }; diff --git a/crates/bevy_scene/src/dynamic_scene.rs b/crates/bevy_scene/src/dynamic_scene.rs index 4936735c6994a..2c16693a5443b 100644 --- a/crates/bevy_scene/src/dynamic_scene.rs +++ b/crates/bevy_scene/src/dynamic_scene.rs @@ -2,7 +2,7 @@ use crate::{ron, DynamicSceneBuilder, Scene, SceneSpawnError}; use bevy_asset::Asset; use bevy_ecs::reflect::ReflectResource; use bevy_ecs::{ - entity::{Entity, hash_map::EntityHashMap, SceneEntityMapper}, + entity::{hash_map::EntityHashMap, Entity, SceneEntityMapper}, reflect::{AppTypeRegistry, ReflectComponent, ReflectMapEntities}, world::World, }; @@ -200,7 +200,8 @@ mod tests { use bevy_ecs::{ component::Component, entity::{ - Entity, hash_map::EntityHashMap, EntityMapper, MapEntities, VisitEntities, VisitEntitiesMut, + hash_map::EntityHashMap, Entity, EntityMapper, MapEntities, VisitEntities, + VisitEntitiesMut, }, hierarchy::Parent, reflect::{AppTypeRegistry, ReflectComponent, ReflectMapEntities, ReflectResource}, diff --git a/crates/bevy_scene/src/scene.rs b/crates/bevy_scene/src/scene.rs index d4baddce814b2..232acf345685e 100644 --- a/crates/bevy_scene/src/scene.rs +++ b/crates/bevy_scene/src/scene.rs @@ -1,7 +1,7 @@ use crate::{DynamicScene, SceneSpawnError}; use bevy_asset::Asset; use bevy_ecs::{ - entity::{Entity, hash_map::EntityHashMap, SceneEntityMapper}, + entity::{hash_map::EntityHashMap, Entity, SceneEntityMapper}, reflect::{AppTypeRegistry, ReflectComponent, ReflectMapEntities, ReflectResource}, world::World, }; diff --git a/crates/bevy_scene/src/scene_spawner.rs b/crates/bevy_scene/src/scene_spawner.rs index 1a9752f3dea35..038f1144322ed 100644 --- a/crates/bevy_scene/src/scene_spawner.rs +++ b/crates/bevy_scene/src/scene_spawner.rs @@ -1,7 +1,7 @@ use crate::{DynamicScene, Scene}; use bevy_asset::{AssetEvent, AssetId, Assets, Handle}; use bevy_ecs::{ - entity::{Entity, hash_map::EntityHashMap}, + entity::{hash_map::EntityHashMap, Entity}, event::{Event, EventCursor, Events}, hierarchy::Parent, reflect::AppTypeRegistry, diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index 3b9ccb8a2f865..d1fc5a89d3cf2 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -515,7 +515,7 @@ mod tests { DynamicScene, DynamicSceneBuilder, }; use bevy_ecs::{ - entity::{Entity, hash_map::EntityHashMap, VisitEntities, VisitEntitiesMut}, + entity::{hash_map::EntityHashMap, Entity, VisitEntities, VisitEntitiesMut}, prelude::{Component, ReflectComponent, ReflectResource, Resource, World}, query::{With, Without}, reflect::{AppTypeRegistry, ReflectMapEntities}, From e8f2df949ebb055560c368a6187e258499d78faf Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 20:19:59 -0800 Subject: [PATCH 10/12] Enable const_generics feature in smallvec for bevy_ecs Was enabled at project level, but not for the individual crate! --- crates/bevy_ecs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/Cargo.toml b/crates/bevy_ecs/Cargo.toml index 3f52188d1cee6..3e539dc732da7 100644 --- a/crates/bevy_ecs/Cargo.toml +++ b/crates/bevy_ecs/Cargo.toml @@ -121,7 +121,7 @@ derive_more = { version = "1", default-features = false, features = [ ] } nonmax = { version = "0.5", default-features = false } arrayvec = { version = "0.7.4", default-features = false, optional = true } -smallvec = { version = "1", features = ["union"] } +smallvec = { version = "1", features = ["union", "const_generics"] } indexmap = { version = "2.5.0", default-features = false } variadics_please = { version = "1.1", default-features = false } critical-section = { version = "1.2.0", optional = true } From 556cdf3a464442c4d44e9f39a30675c72fe867eb Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 20:34:57 -0800 Subject: [PATCH 11/12] Remove cursed DoubleEndedIterator impl --- crates/bevy_ecs/src/entity/hash_set.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/crates/bevy_ecs/src/entity/hash_set.rs b/crates/bevy_ecs/src/entity/hash_set.rs index f02bf0d7fdc50..96b402faeaa75 100644 --- a/crates/bevy_ecs/src/entity/hash_set.rs +++ b/crates/bevy_ecs/src/entity/hash_set.rs @@ -235,15 +235,6 @@ impl ExactSizeIterator for EntityHashSetIter<'_> {} impl FusedIterator for EntityHashSetIter<'_> {} -/// This implementation is somewhat surprising: -/// as hash sets make no guarantees about the order of their elements, -/// [`DoubleEndedIterator::next_back`] is implemented by simply forwarding to the underlying [`Iter::next`]. -impl DoubleEndedIterator for EntityHashSetIter<'_> { - fn next_back(&mut self) -> Option { - self.0.next() - } -} - impl Clone for EntityHashSetIter<'_> { fn clone(&self) -> Self { Self(self.0.clone(), PhantomData) From 48b6b30d4e391598e1f9c7a0a558d65c0920d849 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sun, 19 Jan 2025 21:04:08 -0800 Subject: [PATCH 12/12] Revert `EntityHashSetIter` rename --- crates/bevy_ecs/src/entity/hash_set.rs | 30 +++++++++---------- .../relationship_source_collection.rs | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/bevy_ecs/src/entity/hash_set.rs b/crates/bevy_ecs/src/entity/hash_set.rs index 96b402faeaa75..6fe1f32264cda 100644 --- a/crates/bevy_ecs/src/entity/hash_set.rs +++ b/crates/bevy_ecs/src/entity/hash_set.rs @@ -68,8 +68,8 @@ impl EntityHashSet { /// The iterator element type is `&'a Entity`. /// /// Equivalent to [`HashSet::iter`]. - pub fn iter(&self) -> EntityHashSetIter<'_> { - EntityHashSetIter(self.0.iter(), PhantomData) + pub fn iter(&self) -> Iter<'_> { + Iter(self.0.iter(), PhantomData) } /// Drains elements which are true under the given predicate, @@ -98,10 +98,10 @@ impl DerefMut for EntityHashSet { impl<'a> IntoIterator for &'a EntityHashSet { type Item = &'a Entity; - type IntoIter = EntityHashSetIter<'a>; + type IntoIter = Iter<'a>; fn into_iter(self) -> Self::IntoIter { - EntityHashSetIter((&self.0).into_iter(), PhantomData) + Iter((&self.0).into_iter(), PhantomData) } } @@ -200,16 +200,16 @@ impl FromIterator for EntityHashSet { /// This struct is created by the [`iter`] method on [`EntityHashSet`]. See its documentation for more. /// /// [`iter`]: EntityHashSet::iter -pub struct EntityHashSetIter<'a, S = EntityHash>(hash_set::Iter<'a, Entity>, PhantomData); +pub struct Iter<'a, S = EntityHash>(hash_set::Iter<'a, Entity>, PhantomData); -impl<'a> EntityHashSetIter<'a> { +impl<'a> Iter<'a> { /// Returns the inner [`Iter`](hash_set::Iter). pub fn into_inner(self) -> hash_set::Iter<'a, Entity> { self.0 } } -impl<'a> Deref for EntityHashSetIter<'a> { +impl<'a> Deref for Iter<'a> { type Target = hash_set::Iter<'a, Entity>; fn deref(&self) -> &Self::Target { @@ -217,13 +217,13 @@ impl<'a> Deref for EntityHashSetIter<'a> { } } -impl DerefMut for EntityHashSetIter<'_> { +impl DerefMut for Iter<'_> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } -impl<'a> Iterator for EntityHashSetIter<'a> { +impl<'a> Iterator for Iter<'a> { type Item = &'a Entity; fn next(&mut self) -> Option { @@ -231,30 +231,30 @@ impl<'a> Iterator for EntityHashSetIter<'a> { } } -impl ExactSizeIterator for EntityHashSetIter<'_> {} +impl ExactSizeIterator for Iter<'_> {} -impl FusedIterator for EntityHashSetIter<'_> {} +impl FusedIterator for Iter<'_> {} -impl Clone for EntityHashSetIter<'_> { +impl Clone for Iter<'_> { fn clone(&self) -> Self { Self(self.0.clone(), PhantomData) } } -impl Debug for EntityHashSetIter<'_> { +impl Debug for Iter<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("Iter").field(&self.0).field(&self.1).finish() } } -impl Default for EntityHashSetIter<'_> { +impl Default for Iter<'_> { fn default() -> Self { Self(Default::default(), PhantomData) } } // SAFETY: Iter stems from a correctly behaving `HashSet`. -unsafe impl EntitySetIterator for EntityHashSetIter<'_> {} +unsafe impl EntitySetIterator for Iter<'_> {} /// Owning iterator over the items of an [`EntityHashSet`]. /// diff --git a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs index f0486acda9a1a..d9b26a720d44b 100644 --- a/crates/bevy_ecs/src/relationship/relationship_source_collection.rs +++ b/crates/bevy_ecs/src/relationship/relationship_source_collection.rs @@ -65,7 +65,7 @@ impl RelationshipSourceCollection for Vec { } impl RelationshipSourceCollection for EntityHashSet { - type SourceIter<'a> = core::iter::Copied>; + type SourceIter<'a> = core::iter::Copied>; fn with_capacity(capacity: usize) -> Self { EntityHashSet::with_capacity(capacity)