Skip to content

Commit

Permalink
implement unconditionally read-only params
Browse files Browse the repository at this point in the history
  • Loading branch information
JoJoJet committed Dec 29, 2022
1 parent 09b21fa commit dfdd6bf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,21 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
{}
}
}
ParamAccess::ReadOnly => todo!(),
ParamAccess::ReadOnly => {
quote! {
fn __assert_field_is_read_only_system_param<T: #path::system::ReadOnlySystemParam>() {}
fn __assert_each_field_is_read_only_system_param #impl_generics () #where_clause {
#(
__assert_field_is_read_only_system_param::<#field_types>();
)*
}

// SAFETY: The above code will cause a compile error if each field does not implement `ReadOnlySystemParam`.
// Since each field is `ReadOnlySystemParam`, this can only read from the `World`
unsafe impl #impl_generics #path::system::ReadOnlySystemParam for #struct_name #ty_generics #where_clause
{}
}
}
ParamAccess::Mutable => quote! {},
};

Expand Down

0 comments on commit dfdd6bf

Please sign in to comment.