@@ -13,8 +13,8 @@ use bevy_ecs::{
1313 query:: FilteredAccessSet ,
1414 resource:: Resource ,
1515 system:: {
16- Deferred , ReadOnlySystemParam , Res , SystemBuffer , SystemMeta , SystemParam ,
17- SystemParamValidationError ,
16+ Deferred , ReadOnlySystemParam , ReborrowSystemParam , Res , SystemBuffer , SystemMeta ,
17+ SystemParam , SystemParamValidationError ,
1818 } ,
1919 world:: { unsafe_world_cell:: UnsafeWorldCell , World } ,
2020} ;
@@ -152,6 +152,22 @@ where
152152 pub config_ext : & ' w Config ,
153153}
154154
155+ impl < ' w , ' s , Config , Clear > Gizmos < ' w , ' s , Config , Clear >
156+ where
157+ Config : GizmoConfigGroup ,
158+ Clear : ' static + Send + Sync ,
159+ {
160+ /// Returns a [`Gizmos`] with a shorter lifetime.
161+ /// Useful if you have an `&mut Gizmos` but want a `Gizmos`
162+ pub fn reborrow ( & mut self ) -> Gizmos < ' _ , ' _ , Config , Clear > {
163+ Gizmos {
164+ buffer : self . buffer . reborrow ( ) ,
165+ config : self . config ,
166+ config_ext : self . config_ext ,
167+ }
168+ }
169+ }
170+
155171impl < ' w , ' s , Config , Clear > Deref for Gizmos < ' w , ' s , Config , Clear >
156172where
157173 Config : GizmoConfigGroup ,
@@ -200,16 +216,6 @@ where
200216 type State = GizmosFetchState < Config , Clear > ;
201217 type Item < ' w , ' s > = Gizmos < ' w , ' s , Config , Clear > ;
202218
203- fn reborrow < ' wlong : ' short , ' slong : ' short , ' short > (
204- item : & ' short mut Self :: Item < ' wlong , ' slong > ,
205- ) -> Self :: Item < ' short , ' short > {
206- Gizmos {
207- buffer : item. buffer . reborrow ( ) ,
208- config : item. config ,
209- config_ext : item. config_ext ,
210- }
211- }
212-
213219 fn init_state ( world : & mut World ) -> Self :: State {
214220 GizmosFetchState {
215221 state : GizmosState :: < Config , Clear > :: init_state ( world) ,
@@ -277,6 +283,18 @@ where
277283 }
278284}
279285
286+ impl < Config , Clear > ReborrowSystemParam for Gizmos < ' _ , ' _ , Config , Clear >
287+ where
288+ Config : GizmoConfigGroup ,
289+ Clear : ' static + Send + Sync ,
290+ {
291+ fn reborrow < ' wlong : ' short , ' slong : ' short , ' short > (
292+ item : & ' short mut Self :: Item < ' wlong , ' slong > ,
293+ ) -> Self :: Item < ' short , ' short > {
294+ item. reborrow ( )
295+ }
296+ }
297+
280298#[ expect(
281299 unsafe_code,
282300 reason = "We cannot implement ReadOnlySystemParam without using unsafe code."
0 commit comments