diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index e3122be69c..42db0b5e9f 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -168,7 +168,7 @@ use std::{cell::UnsafeCell, marker::PhantomData}; /// ``` /// /// **Note:** if you omit the `mutable` attribute for a query that doesn't implement -/// `ReadOnlyFetch`, compilation will fail. We insert static checks as in the example above for +/// [`ReadOnlyWorldQuery`], compilation will fail. We insert static checks as in the example above for /// every query component and a nested query. /// (The checks neither affect the runtime, nor pollute your local namespace.) /// @@ -333,7 +333,7 @@ pub unsafe trait WorldQuery: for<'w> WorldQueryGats<'w, _State = Self::State> { /// # Safety /// /// This must only be implemented for read-only [`WorldQuery`]'s. -pub unsafe trait ReadOnlyWorldQuery: WorldQuery {} +pub unsafe trait ReadOnlyWorldQuery: WorldQuery {} /// The [`Fetch`] of a [`WorldQuery`], which declares which data it needs access to pub type QueryFetch<'w, Q> = >::Fetch; diff --git a/crates/bevy_ecs/src/query/iter.rs b/crates/bevy_ecs/src/query/iter.rs index e5bdc4770a..b75c73cbbe 100644 --- a/crates/bevy_ecs/src/query/iter.rs +++ b/crates/bevy_ecs/src/query/iter.rs @@ -306,7 +306,7 @@ where #[inline] fn next(&mut self) -> Option { - // Safety: it is safe to alias for ReadOnlyFetch + // Safety: it is safe to alias for ReadOnlyWorldQuery unsafe { QueryCombinationIter::fetch_next_aliased_unchecked(self) } } diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index 5a9fe5adc0..0900af896f 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -54,6 +54,17 @@ use std::{any::TypeId, borrow::Borrow, fmt::Debug}; /// # bevy_ecs::system::assert_is_system(system); /// ``` /// +/// You can use the [`ReadOnlyWorldQuery`] trait to abstract over read only query generics: +/// ``` +/// # use bevy_ecs::system::Query; +/// # use bevy_ecs::query::{QueryItem, ReadOnlyWorldQuery}; +/// fn system( +/// query: Query, +/// ) { +/// let _: Option> = query.iter().next(); +/// } +/// ``` +/// /// ## Mutable component access /// /// The following example is similar to the previous one, with the exception of `ComponentA`