Skip to content

Commit

Permalink
Document usage of SRes::into_inner on the RenderCommand trait (bevyen…
Browse files Browse the repository at this point in the history
…gine#7224)

# Objective

- Fixes: bevyengine#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`
  • Loading branch information
kurtkuehnert authored and myreprise1 committed Feb 14, 2023
1 parent f852bbf commit a8fb288
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/bevy_ecs/src/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_render/src/render_phase/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,15 @@ impl<P: PhaseItem> DrawFunctions<P> {
pub trait RenderCommand<P: PhaseItem> {
/// 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`].
///
Expand Down

0 comments on commit a8fb288

Please sign in to comment.