From ee2487a6e2b91d6df3cb8ecf98cc71e19965a87d Mon Sep 17 00:00:00 2001 From: Christian Hughes <9044780+ItsDoot@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:06:35 -0500 Subject: [PATCH] Change World::inspect_entity to return an Iterator instead of Vec (#13934) # Objective Fixes #13933. ## Solution Changed the return type. ## Testing Fixed and reused the pre-existing tests for `inspect_entity`. --- ## Migration Guide - `World::inspect_entity` now returns an `Iterator` instead of a `Vec`. If you need a `Vec`, immediately collect the iterator: `world.inspect_entity(entity).collect>()` --- crates/bevy_ecs/src/system/commands/mod.rs | 1 - crates/bevy_ecs/src/world/mod.rs | 17 ++++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index 028182e69f..15e4861fe0 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -1321,7 +1321,6 @@ fn insert_resource(resource: R) -> impl Command { fn log_components(entity: Entity, world: &mut World) { let debug_infos: Vec<_> = world .inspect_entity(entity) - .into_iter() .map(|component_info| component_info.name()) .collect(); info!("Entity {:?}: {:?}", entity, debug_infos); diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index d509eaa349..9ace589952 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -479,7 +479,7 @@ impl World { /// Returns the components of an [`Entity`] through [`ComponentInfo`]. #[inline] - pub fn inspect_entity(&self, entity: Entity) -> Vec<&ComponentInfo> { + pub fn inspect_entity(&self, entity: Entity) -> impl Iterator { let entity_location = self .entities() .get(entity) @@ -498,7 +498,6 @@ impl World { archetype .components() .filter_map(|id| self.components().get_info(id)) - .collect() } /// Returns an [`EntityWorldMut`] for the given `entity` (if it exists) or spawns one if it doesn't exist. @@ -3162,31 +3161,31 @@ mod tests { let bar_id = TypeId::of::(); let baz_id = TypeId::of::(); assert_eq!( - to_type_ids(world.inspect_entity(ent0)), + to_type_ids(world.inspect_entity(ent0).collect()), [Some(foo_id), Some(bar_id), Some(baz_id)].into() ); assert_eq!( - to_type_ids(world.inspect_entity(ent1)), + to_type_ids(world.inspect_entity(ent1).collect()), [Some(foo_id), Some(bar_id)].into() ); assert_eq!( - to_type_ids(world.inspect_entity(ent2)), + to_type_ids(world.inspect_entity(ent2).collect()), [Some(bar_id), Some(baz_id)].into() ); assert_eq!( - to_type_ids(world.inspect_entity(ent3)), + to_type_ids(world.inspect_entity(ent3).collect()), [Some(foo_id), Some(baz_id)].into() ); assert_eq!( - to_type_ids(world.inspect_entity(ent4)), + to_type_ids(world.inspect_entity(ent4).collect()), [Some(foo_id)].into() ); assert_eq!( - to_type_ids(world.inspect_entity(ent5)), + to_type_ids(world.inspect_entity(ent5).collect()), [Some(bar_id)].into() ); assert_eq!( - to_type_ids(world.inspect_entity(ent6)), + to_type_ids(world.inspect_entity(ent6).collect()), [Some(baz_id)].into() ); }