diff --git a/benches/benches/bevy_ecs/scheduling/run_condition.rs b/benches/benches/bevy_ecs/scheduling/run_condition.rs index 1a033f36ef..c88d89b1fe 100644 --- a/benches/benches/bevy_ecs/scheduling/run_condition.rs +++ b/benches/benches/bevy_ecs/scheduling/run_condition.rs @@ -67,8 +67,8 @@ pub fn run_condition_yes_with_query(criterion: &mut Criterion) { group.warm_up_time(core::time::Duration::from_millis(500)); group.measurement_time(core::time::Duration::from_secs(3)); fn empty() {} - fn yes_with_query(query: Query<&TestBool>) -> bool { - query.single().0 + fn yes_with_query(query: Single<&TestBool>) -> bool { + query.0 } for amount in 0..21 { let mut schedule = Schedule::default(); diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 7050c61d58..4cdc3a2473 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -800,8 +800,8 @@ impl App { /// commands.spawn(A); /// } /// - /// fn validate(query: Query<(&A, &B, &C)>) { - /// let (a, b, c) = query.single(); + /// fn validate(query: Option>) { + /// let (a, b, c) = query.unwrap().into_inner(); /// assert_eq!(b, &B(0)); /// assert_eq!(c, &C(0)); /// } @@ -863,8 +863,8 @@ impl App { /// commands.spawn(A); /// } /// - /// fn validate(query: Query<(&A, &B, &C)>) { - /// let (a, b, c) = query.single(); + /// fn validate(query: Option>) { + /// let (a, b, c) = query.unwrap().into_inner(); /// assert_eq!(b, &B(0)); /// assert_eq!(c, &C(2)); /// } @@ -928,8 +928,8 @@ impl App { /// commands.spawn(A); /// } /// - /// fn validate(query: Query<(&A, &B, &C)>) { - /// let (a, b, c) = query.single(); + /// fn validate(query: Option>) { + /// let (a, b, c) = query.unwrap().into_inner(); /// assert_eq!(b, &B(0)); /// assert_eq!(c, &C(0)); /// } @@ -993,8 +993,8 @@ impl App { /// commands.spawn(A); /// } /// - /// fn validate(query: Query<(&A, &B, &C)>) { - /// let (a, b, c) = query.single(); + /// fn validate(query: Option>) { + /// let (a, b, c) = query.unwrap().into_inner(); /// assert_eq!(b, &B(0)); /// assert_eq!(c, &C(2)); /// } diff --git a/crates/bevy_ecs/src/change_detection.rs b/crates/bevy_ecs/src/change_detection.rs index 5a3adac96f..025c3804e7 100644 --- a/crates/bevy_ecs/src/change_detection.rs +++ b/crates/bevy_ecs/src/change_detection.rs @@ -1206,7 +1206,7 @@ mod tests { Mut, NonSendMut, Ref, ResMut, TicksMut, CHECK_TICK_THRESHOLD, MAX_CHANGE_AGE, }, component::{Component, ComponentTicks, Tick}, - system::{IntoSystem, Query, System}, + system::{IntoSystem, Single, System}, world::World, }; @@ -1236,12 +1236,12 @@ mod tests { #[test] fn change_expiration() { - fn change_detected(query: Query>) -> bool { - query.single().is_changed() + fn change_detected(query: Option>>) -> bool { + query.unwrap().is_changed() } - fn change_expired(query: Query>) -> bool { - query.single().is_changed() + fn change_expired(query: Option>>) -> bool { + query.unwrap().is_changed() } let mut world = World::new(); diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index dd6a950f72..cd2452bcbc 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -328,7 +328,7 @@ mod tests { }, system::{ Commands, In, IntoSystem, Local, NonSend, NonSendMut, ParamSet, Query, Res, ResMut, - Resource, StaticSystemParam, System, SystemState, + Resource, Single, StaticSystemParam, System, SystemState, }, world::{EntityMut, FromWorld, World}, }; @@ -1157,12 +1157,15 @@ mod tests { world.insert_resource(A(42)); world.spawn(B(7)); - let mut system_state: SystemState<(Res, Query<&B>, ParamSet<(Query<&C>, Query<&D>)>)> = - SystemState::new(&mut world); + let mut system_state: SystemState<( + Res, + Option>, + ParamSet<(Query<&C>, Query<&D>)>, + )> = SystemState::new(&mut world); let (a, query, _) = system_state.get(&world); assert_eq!(*a, A(42), "returned resource matches initial value"); assert_eq!( - *query.single(), + **query.unwrap(), B(7), "returned component matches initial value" ); @@ -1180,16 +1183,16 @@ mod tests { world.insert_resource(A(42)); world.spawn(B(7)); - let mut system_state: SystemState<(ResMut, Query<&mut B>)> = + let mut system_state: SystemState<(ResMut, Option>)> = SystemState::new(&mut world); // The following line shouldn't compile because the parameters used are not ReadOnlySystemParam // let (a, query) = system_state.get(&world); - let (a, mut query) = system_state.get_mut(&mut world); + let (a, query) = system_state.get_mut(&mut world); assert_eq!(*a, A(42), "returned resource matches initial value"); assert_eq!( - *query.single_mut(), + **query.unwrap(), B(7), "returned component matches initial value" ); @@ -1203,21 +1206,22 @@ mod tests { let mut world = World::default(); let entity = world.spawn(A(1)).id(); - let mut system_state: SystemState>> = SystemState::new(&mut world); + let mut system_state: SystemState>>> = + SystemState::new(&mut world); { let query = system_state.get(&world); - assert_eq!(*query.single(), A(1)); + assert_eq!(**query.unwrap(), A(1)); } { let query = system_state.get(&world); - assert!(query.get_single().is_err()); + assert!(query.is_none()); } world.entity_mut(entity).get_mut::().unwrap().0 = 2; { let query = system_state.get(&world); - assert_eq!(*query.single(), A(2)); + assert_eq!(**query.unwrap(), A(2)); } } diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index f0116e60da..110f6b0b33 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -1384,7 +1384,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> { /// * `&mut T` -> `&T` /// * `&mut T` -> `Ref` /// * [`EntityMut`](crate::world::EntityMut) -> [`EntityRef`](crate::world::EntityRef) - /// + /// /// [`EntityLocation`]: crate::entity::EntityLocation /// [`&Archetype`]: crate::archetype::Archetype #[track_caller] diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 9d06aec04d..df98e49785 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -1214,18 +1214,17 @@ pub trait SystemBuffer: FromWorld + Send + 'static { /// /// // Sound the alarm if there are any criminals who pose a threat. /// fn alert_criminal( -/// settlements: Query<&Settlement>, +/// settlement: Single<&Settlement>, /// criminals: Query<&Criminal>, /// mut alarm: Deferred /// ) { -/// let settlement = settlements.single(); /// for criminal in &criminals { /// // Only sound the alarm if the criminal is a threat. /// // For this example, assume that this check is expensive to run. /// // Since the majority of this system's run-time is dominated /// // by calling `is_threat()`, we defer sounding the alarm to /// // allow this system to run in parallel with other alarm systems. -/// if criminal.is_threat(settlement) { +/// if criminal.is_threat(*settlement) { /// alarm.flag(); /// } /// } diff --git a/crates/bevy_hierarchy/src/query_extension.rs b/crates/bevy_hierarchy/src/query_extension.rs index 5cd8631310..6396ddcfb7 100644 --- a/crates/bevy_hierarchy/src/query_extension.rs +++ b/crates/bevy_hierarchy/src/query_extension.rs @@ -60,9 +60,8 @@ pub trait HierarchyQueryExt<'w, 's, D: QueryData, F: QueryFilter> { /// # use bevy_hierarchy::prelude::*; /// # #[derive(Component)] /// # struct Marker; - /// fn system(query: Query>, children_query: Query<&Children>) { - /// let entity = query.single(); - /// for descendant in children_query.iter_descendants(entity) { + /// fn system(entity: Single>, children_query: Query<&Children>) { + /// for descendant in children_query.iter_descendants(*entity) { /// // Do something! /// } /// } @@ -95,9 +94,8 @@ pub trait HierarchyQueryExt<'w, 's, D: QueryData, F: QueryFilter> { /// # use bevy_hierarchy::prelude::*; /// # #[derive(Component)] /// # struct Marker; - /// fn system(query: Query>, parent_query: Query<&Parent>) { - /// let entity = query.single(); - /// for ancestor in parent_query.iter_ancestors(entity) { + /// fn system(entity: Single>, parent_query: Query<&Parent>) { + /// for ancestor in parent_query.iter_ancestors(*entity) { /// // Do something! /// } /// } diff --git a/examples/2d/2d_viewport_to_world.rs b/examples/2d/2d_viewport_to_world.rs index 5648f30e87..5aa3db91e0 100644 --- a/examples/2d/2d_viewport_to_world.rs +++ b/examples/2d/2d_viewport_to_world.rs @@ -11,11 +11,11 @@ fn main() { } fn draw_cursor( - camera_query: Query<(&Camera, &GlobalTransform)>, + camera_query: Single<(&Camera, &GlobalTransform)>, windows: Query<&Window>, mut gizmos: Gizmos, ) { - let (camera, camera_transform) = camera_query.single(); + let (camera, camera_transform) = *camera_query; let Ok(window) = windows.get_single() else { return; diff --git a/examples/2d/bloom_2d.rs b/examples/2d/bloom_2d.rs index 1f75c0062e..3ffe6e1181 100644 --- a/examples/2d/bloom_2d.rs +++ b/examples/2d/bloom_2d.rs @@ -71,18 +71,17 @@ fn setup( // ------------------------------------------------------------------------------------------------ fn update_bloom_settings( - mut camera: Query<(Entity, Option<&mut Bloom>), With>, - mut text: Query<&mut Text>, + camera: Single<(Entity, Option<&mut Bloom>), With>, + mut text: Single<&mut Text>, mut commands: Commands, keycode: Res>, time: Res