Skip to content

Commit

Permalink
Fixed style and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
vil-mo committed Oct 13, 2024
1 parent 504a500 commit 1d47074
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
31 changes: 15 additions & 16 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
pub fn impl_data_set(_input: TokenStream) -> TokenStream {
let mut tokens = TokenStream::new();
let max_members = 8;
let datas = get_idents(|i| format!("D{i}"), max_members);
let data_types = get_idents(|i| format!("D{i}"), max_members);
let accesses = get_idents(|i| format!("access{i}"), max_members);
let mut member_fn_muts = Vec::new();
for (i, data) in datas.iter().enumerate() {
for (i, data) in data_types.iter().enumerate() {
let fn_name = Ident::new(&format!("d{i}"), Span::call_site());
let index = Index::from(i);
let ordinal = match i {
Expand All @@ -431,13 +431,12 @@ pub fn impl_data_set(_input: TokenStream) -> TokenStream {
3 => "3rd".to_owned(),
x => format!("{x}th"),
};
let comment =
format!("Gets exclusive access to the {ordinal} member of this [`DataSet`].");
let comment = format!("Gets exclusive access to the {ordinal} member of this [`DataSet`].");
member_fn_muts.push(quote! {
#[doc = #comment]
/// No other members may be accessed while this one is active.
pub fn #fn_name(&mut self) -> QueryItem<'_, #data> {
// SAFETY: since it's only possible to create instance of `DataSet` using
// SAFETY: since it's only possible to create instance of `DataSet` using
// `<DataSet as WorldQuery>::fetch`, following safety rules were upheld by the caller.
// - [`WorldQuery::set_table`] or [`WorldQuery::set_archetype`] have been called for `DataSet`,
// so it was called for each `data` (as implementation of those functions for `DataSet` suggests).
Expand All @@ -450,7 +449,7 @@ pub fn impl_data_set(_input: TokenStream) -> TokenStream {
}

for member_count in 1..=max_members {
let data = &datas[0..member_count];
let data = &data_types[0..member_count];
let access = &accesses[0..member_count];
let member_fn_mut = &member_fn_muts[0..member_count];
tokens.extend(TokenStream::from(quote! {
Expand All @@ -472,10 +471,10 @@ pub fn impl_data_set(_input: TokenStream) -> TokenStream {
type Item<'w> = DataSet<'w, (#(#data,)*)>;
type Fetch<'w> = (#(#data::Fetch<'w>,)*);
type State = (#(#data::State,)*);

fn shrink<'wlong: 'wshort, 'wshort>(
item: Self::Item<'wlong>,
) -> Self::Item<'wshort> {
) -> Self::Item<'wshort> {
DataSet {
fetch: Self::shrink_fetch(item.fetch),
entity: item.entity,
Expand All @@ -488,7 +487,7 @@ pub fn impl_data_set(_input: TokenStream) -> TokenStream {
) -> Self::Fetch<'wshort> {
<(#(#data,)*) as WorldQuery>::shrink_fetch(fetch)
}

unsafe fn init_fetch<'w>(
world: UnsafeWorldCell<'w>,
state: &Self::State,
Expand All @@ -500,7 +499,7 @@ pub fn impl_data_set(_input: TokenStream) -> TokenStream {
}

const IS_DENSE: bool = <(#(#data,)*) as WorldQuery>::IS_DENSE;

unsafe fn set_archetype<'w>(
fetch: &mut Self::Fetch<'w>,
state: &Self::State,
Expand All @@ -510,12 +509,12 @@ pub fn impl_data_set(_input: TokenStream) -> TokenStream {
// SAFETY: The invariants are uphold by the caller.
unsafe { <(#(#data,)*) as WorldQuery>::set_archetype(fetch, state, archetype, table); }
}

unsafe fn set_table<'w>(fetch: &mut Self::Fetch<'w>, state: &Self::State, table: &'w Table) {
// SAFETY: The invariants are uphold by the caller.
unsafe { <(#(#data,)*) as WorldQuery>::set_table(fetch, state, table); }
}

unsafe fn fetch<'w>(
fetch: &mut Self::Fetch<'w>,
entity: Entity,
Expand All @@ -527,7 +526,7 @@ pub fn impl_data_set(_input: TokenStream) -> TokenStream {
table_row,
}
}

fn update_component_access(state: &Self::State, filtered_access: &mut FilteredAccess<ComponentId>) {
let (#(#data,)*) = state;

Expand All @@ -544,15 +543,15 @@ pub fn impl_data_set(_input: TokenStream) -> TokenStream {
filtered_access.extend(&#access);
)*
}

fn init_state(world: &mut World) -> Self::State {
<(#(#data,)*) as WorldQuery>::init_state(world)
}

fn get_state(components: &Components) -> Option<Self::State> {
<(#(#data,)*) as WorldQuery>::get_state(components)
}

fn matches_component_set(
state: &Self::State,
set_contains_id: &impl Fn(ComponentId) -> bool,
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ unsafe impl<'__w, T: Component> QueryData for Mut<'__w, T> {
///
/// // This will panic at runtime when the system gets initialized.
/// fn bad_system(
/// mut query: Query<(HealthChangeCalculation, &mut Health)>,
/// mut query: Query<(HealthChangeCalculation, &mut Health)>,
/// ) {
/// // ...
/// }
Expand Down Expand Up @@ -1806,7 +1806,7 @@ unsafe impl<'__w, T: Component> QueryData for Mut<'__w, T> {
/// ```
///
/// [`DataSet`] can also be used in generic contexts that require a [`QueryData`].
///
///
/// ```
/// # use bevy_ecs::prelude::*;
/// # use bevy_ecs::query::QueryData;
Expand Down Expand Up @@ -1845,7 +1845,7 @@ unsafe impl<'__w, T: Component> QueryData for Mut<'__w, T> {
///
/// impl Behavior for Selector {
/// // `update` would not be possible to use, to select between `Run` and `Jump`.
/// // since both `Run` and `Jump` data have mutually exclusive access.
/// // since both `Run` and `Jump` data have mutually exclusive access.
/// type Data = DataSet<'static, (
/// <Run as Behavior>::Data,
/// <Jump as Behavior>::Data,
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod tests {
component::{Component, Components, Tick},
entity::{Entities, Entity},
prelude::{AnyOf, EntityRef},
query::{Added, Changed, Or, With, Without, DataSet},
query::{Added, Changed, DataSet, Or, With, Without},
removal_detection::RemovedComponents,
schedule::{
apply_deferred, common_conditions::resource_exists, Condition, IntoSystemConfigs,
Expand Down Expand Up @@ -810,7 +810,6 @@ mod tests {
run_system(&mut world, sys);
}


#[test]
fn data_set_system() {
fn sys(mut _query: Query<DataSet<(&mut A, &A)>>) {}
Expand Down

0 comments on commit 1d47074

Please sign in to comment.