From 68c94c073253a74fe7b50242b595a897b200ca67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kurt=20K=C3=BChnert?= Date: Mon, 13 Feb 2023 18:44:26 +0000 Subject: [PATCH] Document usage of SRes::into_inner on the RenderCommand trait (#7224) # Objective - Fixes: #7187 Since avoiding the `SRes::into_inner` call does not seem to be possible, this PR tries to at least document its usage. I am not sure if I explained the lifetime issue correctly, please let me know if something is incorrect. ## Solution - Add information about the `SRes::into_inner` usage on both `RenderCommand` and `Res` --- crates/bevy_ecs/src/change_detection.rs | 3 +++ crates/bevy_render/src/render_phase/draw.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/crates/bevy_ecs/src/change_detection.rs b/crates/bevy_ecs/src/change_detection.rs index b77abaa6cb..fd5cccb603 100644 --- a/crates/bevy_ecs/src/change_detection.rs +++ b/crates/bevy_ecs/src/change_detection.rs @@ -389,6 +389,9 @@ impl<'w, T: Resource> Res<'w, T> { } } + /// Due to lifetime limitations of the `Deref` trait, this method can be used to obtain a + /// reference of the [`Resource`] with a lifetime bound to `'w` instead of the lifetime of the + /// struct itself. pub fn into_inner(self) -> &'w T { self.value } diff --git a/crates/bevy_render/src/render_phase/draw.rs b/crates/bevy_render/src/render_phase/draw.rs index f0421b1b64..f839febb5a 100644 --- a/crates/bevy_render/src/render_phase/draw.rs +++ b/crates/bevy_render/src/render_phase/draw.rs @@ -159,7 +159,15 @@ impl DrawFunctions

{ pub trait RenderCommand { /// Specifies the general ECS data (e.g. resources) required by [`RenderCommand::render`]. /// + /// When fetching resources, note that, due to lifetime limitations of the `Deref` trait, + /// [`SRes::into_inner`] must be called on each [`SRes`] reference in the + /// [`RenderCommand::render`] method, instead of being automatically dereferenced as is the + /// case in normal `systems`. + /// /// All parameters have to be read only. + /// + /// [`SRes`]: bevy_ecs::system::lifetimeless::SRes + /// [`SRes::into_inner`]: bevy_ecs::system::lifetimeless::SRes::into_inner type Param: SystemParam + 'static; /// Specifies the ECS data of the view entity required by [`RenderCommand::render`]. ///