Skip to content

Commit

Permalink
Fix merge conflicts with QuerySingle.
Browse files Browse the repository at this point in the history
  • Loading branch information
chescock committed Sep 29, 2024
1 parent 70ced02 commit d1fbada
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions crates/bevy_ecs/src/system/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1645,28 +1645,28 @@ impl<'w, 'q, Q: QueryData, F: QueryFilter> From<&'q mut Query<'w, '_, Q, F>>
/// Use [`Option<QuerySingle<D, F>>`] instead if zero or one matching entities can exist.
///
/// See [`Query`] for more details.
pub struct QuerySingle<'w, D: QueryData, F: QueryFilter = ()> {
pub(crate) item: D::Item<'w>,
pub struct QuerySingle<'w, 's, D: QueryData, F: QueryFilter = ()> {
pub(crate) item: D::Item<'w, 's>,
pub(crate) _filter: PhantomData<F>,
}

impl<'w, D: QueryData, F: QueryFilter> Deref for QuerySingle<'w, D, F> {
type Target = D::Item<'w>;
impl<'w, 's, D: QueryData, F: QueryFilter> Deref for QuerySingle<'w, 's, D, F> {
type Target = D::Item<'w, 's>;

fn deref(&self) -> &Self::Target {
&self.item
}
}

impl<'w, D: QueryData, F: QueryFilter> DerefMut for QuerySingle<'w, D, F> {
impl<'w, 's, D: QueryData, F: QueryFilter> DerefMut for QuerySingle<'w, 's, D, F> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.item
}
}

impl<'w, D: QueryData, F: QueryFilter> QuerySingle<'w, D, F> {
impl<'w, 's, D: QueryData, F: QueryFilter> QuerySingle<'w, 's, D, F> {
/// Returns the inner item with ownership.
pub fn into_inner(self) -> D::Item<'w> {
pub fn into_inner(self) -> D::Item<'w, 's> {
self.item
}
}
20 changes: 10 additions & 10 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ fn assert_component_access_compatibility(

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

fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
Query::init_state(world, system_meta)
Expand Down Expand Up @@ -427,11 +427,11 @@ unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam

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

fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
QuerySingle::init_state(world, system_meta)
Expand Down Expand Up @@ -488,14 +488,14 @@ unsafe impl<'a, D: QueryData + 'static, F: QueryFilter + 'static> SystemParam
}

// SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
unsafe impl<'a, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam
for QuerySingle<'a, D, F>
unsafe impl<D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam
for QuerySingle<'_, '_, D, F>
{
}

// SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
unsafe impl<'a, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam
for Option<QuerySingle<'a, D, F>>
unsafe impl<D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam
for Option<QuerySingle<'_, '_, D, F>>
{
}

Expand Down

0 comments on commit d1fbada

Please sign in to comment.