Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions crates/bevy_ecs/macros/src/query_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@ pub fn derive_query_data_impl(input: TokenStream) -> TokenStream {
}
}

impl #user_impl_generics #path::query::ReborrowQueryData
for #read_only_struct_name #user_ty_generics #user_where_clauses
// Make these HRTBs with an unused lifetime parameter to allow trivial constraints
// See https://github.com/rust-lang/rust/issues/48214
where #(for<'__a> #field_types: #path::query::QueryData<ReadOnly: #path::query::ReborrowQueryData>,)* {
fn reborrow<'wlong: 'short, 'slong: 'short, 'short>(
item: &'short mut Self::Item<'wlong, 'slong>,
) -> Self::Item<'short, 'short> {
#read_only_item_struct_name {
#(
#field_members: <#read_only_field_types>::reborrow(&mut item.#field_members),
)*
}
}
}

impl #user_impl_generics #path::query::ReleaseStateQueryData
for #read_only_struct_name #user_ty_generics #user_where_clauses
// Make these HRTBs with an unused lifetime parameter to allow trivial constraints
Expand Down Expand Up @@ -346,6 +362,22 @@ pub fn derive_query_data_impl(input: TokenStream) -> TokenStream {
}
}

impl #user_impl_generics #path::query::ReborrowQueryData
for #struct_name #user_ty_generics #user_where_clauses
// Make these HRTBs with an unused lifetime parameter to allow trivial constraints
// See https://github.com/rust-lang/rust/issues/48214
where #(for<'__a> #field_types: #path::query::ReborrowQueryData,)* {
fn reborrow<'wlong: 'short, 'slong: 'short, 'short>(
item: &'short mut Self::Item<'wlong, 'slong>,
) -> Self::Item<'short, 'short> {
#item_struct_name {
#(
#field_members: <#field_types>::reborrow(&mut item.#field_members),
)*
}
}
}

impl #user_impl_generics #path::query::ReleaseStateQueryData
for #struct_name #user_ty_generics #user_where_clauses
// Make these HRTBs with an unused lifetime parameter to allow trivial constraints
Expand Down
15 changes: 15 additions & 0 deletions crates/bevy_ecs/src/change_detection/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,21 @@ impl<'w, T: ?Sized> Ref<'w, T> {
self.ticks.last_run = last_run;
self.ticks.this_run = this_run;
}

/// Returns a `Mut<>` with a smaller lifetime.
/// This is useful if you have `&Ref<T>`, but you need a `Ref<T>`.
Comment on lines +364 to +365
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns a `Mut<>` with a smaller lifetime.
/// This is useful if you have `&Ref<T>`, but you need a `Ref<T>`.
/// Returns a [`Mut<>`] with a smaller lifetime.
/// This is useful if you have &[`Ref<T>`], but you need a [`Ref<T>`].

pub fn reborrow(&self) -> Ref<'_, T> {
Ref {
value: self.value,
ticks: ComponentTicksRef {
added: self.ticks.added,
changed: self.ticks.changed,
changed_by: self.ticks.changed_by,
last_run: self.ticks.last_run,
this_run: self.ticks.this_run,
},
}
Comment on lines +367 to +376
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ref {
value: self.value,
ticks: ComponentTicksRef {
added: self.ticks.added,
changed: self.ticks.changed,
changed_by: self.ticks.changed_by,
last_run: self.ticks.last_run,
this_run: self.ticks.this_run,
},
}
Ref {
ticks: self.ticks.clone(),
..*self
}

}
}

impl<'w, 'a, T> IntoIterator for &'a Ref<'w, T>
Expand Down
Loading