bevy
bevy copied to clipboard
Add subtrait for reborrowing QueryData types
Objective
Allow reborrowing for QueryData types. The end goal here is to work towards a fast System::run_iter api, avoiding the overhead of get_param with each iteration. Funnily enough the only system param that actually needs this is Single, but it seems worthwhile to have anyways
Next steps:
-
ReborrowSystemParam -
SystemIter
Solution
- Add
ReborrowQueryData, an optional subtrait (though almost all QueryData types should implement this in practice)
/// A [`QueryData`] that's able to be reborrowed, converting a reference into
/// an owned struct with a shorter lifetime.
pub trait ReborrowQueryData: QueryData {
/// Returns a `QueryData` item with a smaller lifetime.
fn reborrow<'wlong: 'short, 'slong: 'short, 'short>(
item: &'short mut Self::Item<'wlong, 'slong>,
) -> Self::Item<'short, 'short>;
}