diff --git a/benches/benches/bevy_ecs/iteration/iter_simple_system.rs b/benches/benches/bevy_ecs/iteration/iter_simple_system.rs index 039de135c2439..f120b0015f169 100644 --- a/benches/benches/bevy_ecs/iteration/iter_simple_system.rs +++ b/benches/benches/bevy_ecs/iteration/iter_simple_system.rs @@ -30,7 +30,7 @@ impl Benchmark { } fn query_system(mut query: Query<(&Velocity, &mut Position)>) { - for (velocity, mut position) in query.iter_mut() { + for (velocity, mut position) in &mut query { position.0 += velocity.0; } } diff --git a/benches/benches/bevy_ecs/world/commands.rs b/benches/benches/bevy_ecs/world/commands.rs index a35e20033b00a..7688ce1d8759d 100644 --- a/benches/benches/bevy_ecs/world/commands.rs +++ b/benches/benches/bevy_ecs/world/commands.rs @@ -92,7 +92,7 @@ pub fn insert_commands(criterion: &mut Criterion) { bencher.iter(|| { let mut commands = Commands::new(&mut command_queue, &world); - for entity in entities.iter() { + for entity in &entities { commands .entity(*entity) .insert_bundle((Matrix::default(), Vec3::default())); @@ -112,7 +112,7 @@ pub fn insert_commands(criterion: &mut Criterion) { bencher.iter(|| { let mut commands = Commands::new(&mut command_queue, &world); let mut values = Vec::with_capacity(entity_count); - for entity in entities.iter() { + for entity in &entities { values.push((*entity, (Matrix::default(), Vec3::default()))); } commands.insert_or_spawn_batch(values); diff --git a/benches/benches/bevy_reflect/struct.rs b/benches/benches/bevy_reflect/struct.rs index a879828ab4add..613bd13d19b4c 100644 --- a/benches/benches/bevy_reflect/struct.rs +++ b/benches/benches/bevy_reflect/struct.rs @@ -43,7 +43,7 @@ fn concrete_struct_field(criterion: &mut Criterion) { .collect::>(); bencher.iter(|| { - for name in field_names.iter() { + for name in &field_names { s.field(black_box(name)); } }); diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 92ecf16c2599f..ee70d801ef952 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -183,7 +183,7 @@ pub fn animation_player( mut transforms: Query<&mut Transform>, children: Query<&Children>, ) { - for (entity, mut player) in animation_players.iter_mut() { + for (entity, mut player) in &mut animation_players { if let Some(animation_clip) = animations.get(&player.animation_clip) { // Continue if paused unless the `AnimationPlayer` was changed // This allow the animation to still be updated if the player.elapsed field was manually updated in pause diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index da1fc3b0cb57d..e9e8576352346 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -110,7 +110,7 @@ impl AssetServer { { let mut loaders = self.server.loaders.write(); let loader_index = loaders.len(); - for extension in loader.extensions().iter() { + for extension in loader.extensions() { self.server .extension_to_loader_index .write() diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index 9470121bc49f3..c69e8104dc15f 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -236,7 +236,7 @@ pub fn prepare_core_3d_depth_textures( >, ) { let mut textures = HashMap::default(); - for (entity, camera) in views_3d.iter() { + for (entity, camera) in &views_3d { if let Some(physical_target_size) = camera.physical_target_size { let cached_texture = textures .entry(camera.target.clone()) diff --git a/crates/bevy_ecs/README.md b/crates/bevy_ecs/README.md index f967a752187aa..7c8f8f0f300ee 100644 --- a/crates/bevy_ecs/README.md +++ b/crates/bevy_ecs/README.md @@ -78,7 +78,7 @@ use bevy_ecs::prelude::*; struct Position { x: f32, y: f32 } fn print_position(query: Query<(Entity, &Position)>) { - for (entity, position) in query.iter() { + for (entity, position) in &query { println!("Entity {:?} is at position: x {}, y {}", entity, position.x, position.y); } } @@ -130,7 +130,7 @@ struct Velocity { x: f32, y: f32 } // This system moves each entity with a Position and Velocity component fn movement(mut query: Query<(&mut Position, &Velocity)>) { - for (mut position, velocity) in query.iter_mut() { + for (mut position, velocity) in &mut query { position.x += velocity.x; position.y += velocity.y; } @@ -176,7 +176,7 @@ struct Alive; // Gets the Position component of all Entities with Player component and without the Alive // component. fn system(query: Query<&Position, (With, Without)>) { - for position in query.iter() { + for position in &query { } } ``` @@ -197,13 +197,13 @@ struct Velocity { x: f32, y: f32 } // Gets the Position component of all Entities whose Velocity has changed since the last run of the System fn system_changed(query: Query<&Position, Changed>) { - for position in query.iter() { + for position in &query { } } // Gets the Position component of all Entities that had a Velocity component added since the last run of the System fn system_added(query: Query<&Position, Added>) { - for position in query.iter() { + for position in &query { } } ``` diff --git a/crates/bevy_ecs/examples/change_detection.rs b/crates/bevy_ecs/examples/change_detection.rs index 1a3e135b654e2..8477a5164f44a 100644 --- a/crates/bevy_ecs/examples/change_detection.rs +++ b/crates/bevy_ecs/examples/change_detection.rs @@ -79,24 +79,24 @@ fn print_changed_entities( entity_with_added_component: Query>, entity_with_mutated_component: Query<(Entity, &Age), Changed>, ) { - for entity in entity_with_added_component.iter() { + for entity in &entity_with_added_component { println!(" {:?} has it's first birthday!", entity); } - for (entity, value) in entity_with_mutated_component.iter() { + for (entity, value) in &entity_with_mutated_component { println!(" {:?} is now {:?} frames old", entity, value); } } // This system iterates over all entities and increases their age in every frame fn age_all_entities(mut entities: Query<&mut Age>) { - for mut age in entities.iter_mut() { + for mut age in &mut entities { age.frames += 1; } } // This system iterates over all entities in every frame and despawns entities older than 2 frames fn remove_old_entities(mut commands: Commands, entities: Query<(Entity, &Age)>) { - for (entity, age) in entities.iter() { + for (entity, age) in &entities { if age.frames > 2 { println!(" despawning {:?} due to age > 2", entity); commands.entity(entity).despawn(); diff --git a/crates/bevy_ecs/macros/src/fetch.rs b/crates/bevy_ecs/macros/src/fetch.rs index 2bbb08cc98c78..0b44e3c33c2ae 100644 --- a/crates/bevy_ecs/macros/src/fetch.rs +++ b/crates/bevy_ecs/macros/src/fetch.rs @@ -134,7 +134,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream { let mut field_idents = Vec::new(); let mut field_types = Vec::new(); - for field in fields.iter() { + for field in fields { let WorldQueryFieldInfo { is_ignored, attrs } = read_world_query_field_info(field); let field_ident = field.ident.as_ref().unwrap().clone(); diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 2c10a87eb3743..e022483fa836c 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -84,7 +84,7 @@ use std::{ /// # struct Expired; /// # /// fn dispose_expired_food(mut commands: Commands, query: Query>) { -/// for food_entity in query.iter() { +/// for food_entity in &query { /// commands.entity(food_entity).despawn(); /// } /// } diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 33b3f47529c2e..d2f0541ce20a0 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -79,7 +79,7 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// } /// /// fn my_system(query: Query) { -/// for q in query.iter() { +/// for q in &query { /// // Note the type of the returned item. /// let q: MyQueryItem<'_> = q; /// q.foo; @@ -130,11 +130,11 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// /// fn my_system(mut health_query: Query) { /// // Iterator's item is `HealthQueryReadOnlyItem`. -/// for health in health_query.iter() { +/// for health in &health_query { /// println!("Total: {}", health.total()); /// } /// // Iterator's item is `HealthQueryItem`. -/// for mut health in health_query.iter_mut() { +/// for mut health in &mut health_query { /// health.damage(1.0); /// println!("Total (mut): {}", health.total()); /// } @@ -158,7 +158,7 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// } /// /// fn my_system(mut my_query: Query<(FooReadOnly, FooReadOnly)>) { -/// for (i1, i2) in my_query.iter_mut() { +/// for (i1, i2) in &mut my_query { /// let _: FooReadOnlyItem<'_> = i1; /// let _: FooReadOnlyItem<'_> = i2; /// } @@ -254,7 +254,7 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// /// // You can also compose derived queries with regular ones in tuples. /// fn my_system(query: Query<(&Foo, MyQuery, FooQuery)>) { -/// for (foo, my_query, foo_query) in query.iter() { +/// for (foo, my_query, foo_query) in &query { /// foo; my_query; foo_query; /// } /// } @@ -279,7 +279,7 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// } /// /// fn my_system(query: Query) { -/// for _ in query.iter() {} +/// for _ in &query {} /// } /// /// # bevy_ecs::system::assert_is_system(my_system); @@ -311,7 +311,7 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// } /// /// fn my_system(query: Query>) { -/// for _ in query.iter() {} +/// for _ in &query {} /// } /// /// # bevy_ecs::system::assert_is_system(my_system); @@ -1087,7 +1087,7 @@ unsafe impl<'w, T: Fetch<'w>> Fetch<'w> for OptionFetch { /// # struct Transform {}; /// # /// fn print_moving_objects_system(query: Query<(&Name, ChangeTrackers)>) { -/// for (name, tracker) in query.iter() { +/// for (name, tracker) in &query { /// if tracker.is_changed() { /// println!("Entity moved: {:?}", name); /// } else { diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index 919b7dd1ec4cd..23392fd49db77 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -36,7 +36,7 @@ use super::ReadOnlyWorldQuery; /// # struct Name { name: &'static str }; /// # /// fn compliment_entity_system(query: Query<&Name, With>) { -/// for name in query.iter() { +/// for name in &query { /// println!("{} is looking lovely today!", name.name); /// } /// } @@ -177,7 +177,7 @@ impl Copy for WithFetch {} /// # struct Name { name: &'static str }; /// # /// fn no_permit_system(query: Query<&Name, Without>) { -/// for name in query.iter() { +/// for name in &query{ /// println!("{} has no permit!", name.name); /// } /// } @@ -324,7 +324,7 @@ impl Copy for WithoutFetch {} /// # struct Style {}; /// # /// fn print_cool_entity_system(query: Query, Changed