bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Add subtrait for reborrowing QueryData types

Open ecoskey opened this issue 2 months ago • 0 comments

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:

  1. ReborrowSystemParam
  2. 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>;
}

ecoskey avatar Dec 04 '25 02:12 ecoskey