Skip to content

Commit d217110

Browse files
authored
Merge branch 'main' into better-validate-warnings
2 parents 240a427 + 8316d89 commit d217110

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

crates/bevy_ecs/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ pub mod prelude {
5858
},
5959
system::{
6060
Commands, Deferred, EntityCommand, EntityCommands, In, InMut, InRef, IntoSystem, Local,
61-
NonSend, NonSendMut, ParallelCommands, ParamSet, Query, QuerySingle, ReadOnlySystem,
62-
Res, ResMut, Resource, System, SystemIn, SystemInput, SystemParamBuilder,
61+
NonSend, NonSendMut, ParallelCommands, ParamSet, Query, ReadOnlySystem, Res, ResMut,
62+
Resource, Single, System, SystemIn, SystemInput, SystemParamBuilder,
6363
SystemParamFunction,
6464
},
6565
world::{

crates/bevy_ecs/src/system/query.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1639,29 +1639,29 @@ impl<'w, 'q, Q: QueryData, F: QueryFilter> From<&'q mut Query<'w, '_, Q, F>>
16391639
/// This [`SystemParam`](crate::system::SystemParam) fails validation if zero or more than one matching entity exists.
16401640
/// This will cause systems that use this parameter to be skipped.
16411641
///
1642-
/// Use [`Option<QuerySingle<D, F>>`] instead if zero or one matching entities can exist.
1642+
/// Use [`Option<Single<D, F>>`] instead if zero or one matching entities can exist.
16431643
///
16441644
/// See [`Query`] for more details.
1645-
pub struct QuerySingle<'w, D: QueryData, F: QueryFilter = ()> {
1645+
pub struct Single<'w, D: QueryData, F: QueryFilter = ()> {
16461646
pub(crate) item: D::Item<'w>,
16471647
pub(crate) _filter: PhantomData<F>,
16481648
}
16491649

1650-
impl<'w, D: QueryData, F: QueryFilter> Deref for QuerySingle<'w, D, F> {
1650+
impl<'w, D: QueryData, F: QueryFilter> Deref for Single<'w, D, F> {
16511651
type Target = D::Item<'w>;
16521652

16531653
fn deref(&self) -> &Self::Target {
16541654
&self.item
16551655
}
16561656
}
16571657

1658-
impl<'w, D: QueryData, F: QueryFilter> DerefMut for QuerySingle<'w, D, F> {
1658+
impl<'w, D: QueryData, F: QueryFilter> DerefMut for Single<'w, D, F> {
16591659
fn deref_mut(&mut self) -> &mut Self::Target {
16601660
&mut self.item
16611661
}
16621662
}
16631663

1664-
impl<'w, D: QueryData, F: QueryFilter> QuerySingle<'w, D, F> {
1664+
impl<'w, D: QueryData, F: QueryFilter> Single<'w, D, F> {
16651665
/// Returns the inner item with ownership.
16661666
pub fn into_inner(self) -> D::Item<'w> {
16671667
self.item

crates/bevy_ecs/src/system/system_param.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
QuerySingleError, QueryState, ReadOnlyQueryData,
1111
},
1212
storage::{ResourceData, SparseSetIndex},
13-
system::{Query, QuerySingle, SystemMeta},
13+
system::{Query, Single, SystemMeta},
1414
world::{unsafe_world_cell::UnsafeWorldCell, DeferredWorld, FromWorld, World},
1515
};
1616
use bevy_ecs_macros::impl_param_set;
@@ -367,11 +367,9 @@ fn assert_component_access_compatibility(
367367

368368
// SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If
369369
// this Query conflicts with any prior access, a panic will occur.
370-
unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam
371-
for QuerySingle<'a, D, F>
372-
{
370+
unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam for Single<'a, D, F> {
373371
type State = QueryState<D, F>;
374-
type Item<'w, 's> = QuerySingle<'w, D, F>;
372+
type Item<'w, 's> = Single<'w, D, F>;
375373

376374
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
377375
Query::init_state(world, system_meta)
@@ -399,7 +397,7 @@ unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam
399397
unsafe { state.get_single_unchecked_manual(world, system_meta.last_run, change_tick) };
400398
let single =
401399
result.expect("The query was expected to contain exactly one matching entity.");
402-
QuerySingle {
400+
Single {
403401
item: single,
404402
_filter: PhantomData,
405403
}
@@ -428,13 +426,13 @@ unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam
428426
// SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If
429427
// this Query conflicts with any prior access, a panic will occur.
430428
unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam
431-
for Option<QuerySingle<'a, D, F>>
429+
for Option<Single<'a, D, F>>
432430
{
433431
type State = QueryState<D, F>;
434-
type Item<'w, 's> = Option<QuerySingle<'w, D, F>>;
432+
type Item<'w, 's> = Option<Single<'w, D, F>>;
435433

436434
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
437-
QuerySingle::init_state(world, system_meta)
435+
Single::init_state(world, system_meta)
438436
}
439437

440438
unsafe fn new_archetype(
@@ -443,7 +441,7 @@ unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam
443441
system_meta: &mut SystemMeta,
444442
) {
445443
// SAFETY: Delegate to existing `SystemParam` implementations.
446-
unsafe { QuerySingle::new_archetype(state, archetype, system_meta) };
444+
unsafe { Single::new_archetype(state, archetype, system_meta) };
447445
}
448446

449447
#[inline]
@@ -458,7 +456,7 @@ unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam
458456
let result =
459457
unsafe { state.get_single_unchecked_manual(world, system_meta.last_run, change_tick) };
460458
match result {
461-
Ok(single) => Some(QuerySingle {
459+
Ok(single) => Some(Single {
462460
item: single,
463461
_filter: PhantomData,
464462
}),
@@ -489,13 +487,13 @@ unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam
489487

490488
// SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
491489
unsafe impl<'a, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam
492-
for QuerySingle<'a, D, F>
490+
for Single<'a, D, F>
493491
{
494492
}
495493

496494
// SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
497495
unsafe impl<'a, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam
498-
for Option<QuerySingle<'a, D, F>>
496+
for Option<Single<'a, D, F>>
499497
{
500498
}
501499

examples/ecs/fallible_params.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//!
44
//! Fallible parameters include:
55
//! - [`Res<R>`], [`ResMut<R>`] - If resource doesn't exist.
6-
//! - [`QuerySingle<D, F>`] - If there is no or more than one entities matching.
7-
//! - [`Option<QuerySingle<D, F>>`] - If there are more than one entities matching.
6+
//! - [`Single<D, F>`] - If there is no or more than one entities matching.
7+
//! - [`Option<Single<D, F>>`] - If there are more than one entities matching.
88
99
use bevy::prelude::*;
1010
use rand::Rng;
@@ -121,9 +121,9 @@ fn move_targets(mut enemies: Query<(&mut Transform, &mut Enemy)>, time: Res<Time
121121
/// If there are too many enemies, the player will cease all action (the system will not run).
122122
fn move_pointer(
123123
// `QuerySingle` ensures the system runs ONLY when exactly one matching entity exists.
124-
mut player: QuerySingle<(&mut Transform, &Player)>,
124+
mut player: Single<(&mut Transform, &Player)>,
125125
// `Option<QuerySingle>` ensures that the system runs ONLY when zero or one matching entity exists.
126-
enemy: Option<QuerySingle<&Transform, (With<Enemy>, Without<Player>)>>,
126+
enemy: Option<Single<&Transform, (With<Enemy>, Without<Player>)>>,
127127
time: Res<Time>,
128128
) {
129129
let (player_transform, player) = &mut *player;

0 commit comments

Comments
 (0)