diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index f13b878bb0e309..fc2944ad51b1f1 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -439,7 +439,7 @@ pub unsafe trait WorldQuery { /// Adds component access for when [`WorldQuery`] is not an exact match. /// i.e. Option<&T> where the matched archetypes don't necessarily contain - /// the data the WorldQuery takes access to in [`update_component_access`] + /// the data the WorldQuery takes access to in [`Self::update_component_access`] fn optional_access( state: &Self::State, access: &mut Access, diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index e6bf4f115df403..7272cf2fdbd076 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -140,12 +140,12 @@ impl QueryState { /// This is used to transform a [`Query`](crate::system::Query) into a more generic [`Query`](crate::system::Query). /// This can be useful for passsing to another function tha might take the more generalize query. - /// See [`Query::restrict_fetch`](crate::system::Query::restrict_fetch) for more details. + /// See [`Query::transmute_fetch`](crate::system::Query::transmute_fetch) for more details. /// - /// You should not call `update_archetypes` on the returned [`QueryState`] as the result will be unpredictable. + /// You should not call [`update_archetypes`](Self::update_archetypes) on the returned [`QueryState`] as the result will be unpredictable. /// You might end up with a mix of archetypes that only matched the original query + archetypes that only match /// the new [`QueryState`]. Most of the safe methods on [`QueryState`] call [`QueryState::update_archetypes`] internally. - pub(crate) fn restrict_fetch( + pub(crate) fn transmute_fetch( &self, components: &Components, ) -> QueryState { @@ -1615,7 +1615,7 @@ mod tests { world.spawn((A(22), B)); let query_state = world.query::<(&A, &B)>(); - let mut new_query_state = query_state.restrict_fetch::<&A>(world.components()); + let mut new_query_state = query_state.transmute_fetch::<&A>(world.components()); assert_eq!(new_query_state.iter(&world).len(), 1); let a = new_query_state.single(&world); @@ -1629,7 +1629,7 @@ mod tests { world.spawn((A(23), B, C(5))); let query_state = world.query_filtered::<(&A, &B), Without>(); - let mut new_query_state = query_state.restrict_fetch::<&A>(world.components()); + let mut new_query_state = query_state.transmute_fetch::<&A>(world.components()); // even though we change the query to not have Without, we do not get the component with C. let a = new_query_state.single(&world); @@ -1643,7 +1643,7 @@ mod tests { let entity = world.spawn(A(10)).id(); let q = world.query::<()>(); - let mut q = q.restrict_fetch::(world.components()); + let mut q = q.transmute_fetch::(world.components()); assert_eq!(q.single(&world), entity); } @@ -1653,11 +1653,11 @@ mod tests { world.spawn(A(10)); let q = world.query::<&A>(); - let mut new_q = q.restrict_fetch::>(world.components()); + let mut new_q = q.transmute_fetch::>(world.components()); assert!(new_q.single(&world).is_added()); let q = world.query::>(); - let _ = q.restrict_fetch::<&A>(world.components()); + let _ = q.transmute_fetch::<&A>(world.components()); } #[test] @@ -1666,8 +1666,8 @@ mod tests { world.spawn(A(10)); let q = world.query::<&mut A>(); - let _ = q.restrict_fetch::>(world.components()); - let _ = q.restrict_fetch::<&A>(world.components()); + let _ = q.transmute_fetch::>(world.components()); + let _ = q.transmute_fetch::<&A>(world.components()); } #[test] @@ -1676,7 +1676,7 @@ mod tests { world.spawn(A(10)); let q = world.query::(); - let _ = q.restrict_fetch::(world.components()); + let _ = q.transmute_fetch::(world.components()); } #[test] @@ -1685,7 +1685,7 @@ mod tests { world.spawn((A(22), B)); let query_state = world.query::<(Option<&A>, &B)>(); - let _ = query_state.restrict_fetch::>(world.components()); + let _ = query_state.transmute_fetch::>(world.components()); } #[test] @@ -1697,7 +1697,7 @@ mod tests { world.spawn(A(22)); let query_state = world.query::<&A>(); - let mut _new_query_state = query_state.restrict_fetch::<(&A, &B)>(world.components()); + let mut _new_query_state = query_state.transmute_fetch::<(&A, &B)>(world.components()); } #[test] @@ -1709,7 +1709,7 @@ mod tests { world.spawn(A(22)); let query_state = world.query_filtered::<(&A, &B), Added>(); - let mut _new_query_state = query_state.restrict_fetch::<&A>(world.components()); + let mut _new_query_state = query_state.transmute_fetch::<&A>(world.components()); } #[test] @@ -1719,7 +1719,7 @@ mod tests { world.spawn(A(22)); let query_state = world.query::<&A>(); - let mut _new_query_state = query_state.restrict_fetch::<&mut A>(world.components()); + let mut _new_query_state = query_state.transmute_fetch::<&mut A>(world.components()); } #[test] @@ -1731,7 +1731,7 @@ mod tests { world.spawn(C(22)); let query_state = world.query::>(); - let mut new_query_state = query_state.restrict_fetch::<&A>(world.components()); + let mut new_query_state = query_state.transmute_fetch::<&A>(world.components()); let x = new_query_state.single(&world); assert_eq!(x.0, 1234); } @@ -1743,7 +1743,7 @@ mod tests { world.init_component::(); let q = world.query::(); - let _ = q.restrict_fetch::<&A>(world.components()); + let _ = q.transmute_fetch::<&A>(world.components()); } } } diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index ef36581177fdf4..ca97f4e9f3a529 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -433,7 +433,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> { /// } /// /// fn system_2(mut query: Query<(&mut A, &B)>) { - /// let mut lens = query.restrict_fetch::<&A>(); + /// let mut lens = query.transmute_fetch::<&A>(); /// function_that_uses_a_query_lens(&mut lens); /// } /// @@ -441,8 +441,8 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> { /// # schedule.add_systems((system_1, system_2)); /// # schedule.run(&mut world); /// ``` - pub fn restrict_fetch(&mut self) -> QueryLens<'_, NewQ> { - let new_state = self.state.restrict_fetch(self.world.components()); + pub fn transmute_fetch(&mut self) -> QueryLens<'_, NewQ> { + let new_state = self.state.transmute_fetch(self.world.components()); QueryLens { state: new_state, @@ -454,7 +454,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> { /// helper method to get a [`QueryLens`] with the same fetch as the existing query pub fn into_query_lens(&mut self) -> QueryLens<'_, Q> { - self.restrict_fetch() + self.transmute_fetch() } /// Returns an [`Iterator`] over the read-only query items.