Skip to content

Commit 68c94c0

Browse files
committed
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`
1 parent 39bf45c commit 68c94c0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

crates/bevy_ecs/src/change_detection.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ impl<'w, T: Resource> Res<'w, T> {
389389
}
390390
}
391391

392+
/// Due to lifetime limitations of the `Deref` trait, this method can be used to obtain a
393+
/// reference of the [`Resource`] with a lifetime bound to `'w` instead of the lifetime of the
394+
/// struct itself.
392395
pub fn into_inner(self) -> &'w T {
393396
self.value
394397
}

crates/bevy_render/src/render_phase/draw.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,15 @@ impl<P: PhaseItem> DrawFunctions<P> {
159159
pub trait RenderCommand<P: PhaseItem> {
160160
/// Specifies the general ECS data (e.g. resources) required by [`RenderCommand::render`].
161161
///
162+
/// When fetching resources, note that, due to lifetime limitations of the `Deref` trait,
163+
/// [`SRes::into_inner`] must be called on each [`SRes`] reference in the
164+
/// [`RenderCommand::render`] method, instead of being automatically dereferenced as is the
165+
/// case in normal `systems`.
166+
///
162167
/// All parameters have to be read only.
168+
///
169+
/// [`SRes`]: bevy_ecs::system::lifetimeless::SRes
170+
/// [`SRes::into_inner`]: bevy_ecs::system::lifetimeless::SRes::into_inner
163171
type Param: SystemParam + 'static;
164172
/// Specifies the ECS data of the view entity required by [`RenderCommand::render`].
165173
///

0 commit comments

Comments
 (0)