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`
This commit is contained in:
Kurt Kühnert 2023-02-13 18:44:26 +00:00
parent 39bf45cf5e
commit 68c94c0732
2 changed files with 11 additions and 0 deletions

View file

@ -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
}

View file

@ -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`].
///