Skip to content

Commit

Permalink
Failed attempt at a stateless query helper
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Feb 7, 2022
1 parent f241492 commit 71b5fd4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
event::Events,
query::{FilterFetch, QueryState, WorldQuery},
storage::{Column, SparseSet, Storages},
system::Resource,
system::{Query, Resource},
};
use std::{
any::TypeId,
Expand Down Expand Up @@ -569,6 +569,27 @@ impl World {
QueryState::new(self)
}

/// Returns a [`Query`] for the given [`WorldQuery`]
///
/// To access a [`Query`] at the same time as other parts of the [`World`],
/// consider using [`SystemState`](crate::system::SystemState) instead.
///
/// ## Warning
/// This method is primarily intended for integration testing purposes.
/// No state is cached, or provided to be cached, which means:
/// 1. Overhead will be measurably higher.
/// 2. [`Added`](crate::query::Added) and [`Changed`](crate::query::Changed) query filters will be true for all compoenents.
#[inline]
pub fn query_stateless<Q: WorldQuery, F: WorldQuery>(&mut self) -> Query<Q, F>
where
F::Fetch: FilterFetch,
{
let query_state = QueryState::new(self);

// SAFE: we have unique mutable access to the world
unsafe { Query::new(self, &query_state, self.change_tick(), self.change_tick()) }
}

/// Returns an iterator of entities that had components of type `T` removed
/// since the last call to [`World::clear_trackers`].
pub fn removed<T: Component>(&self) -> std::iter::Cloned<std::slice::Iter<'_, Entity>> {
Expand Down

0 comments on commit 71b5fd4

Please sign in to comment.