mirror of
https://github.com/bevyengine/bevy
synced 2024-12-22 02:53:07 +00:00
7d69d3195f
# Objective It would be convenient to be able to call functions with `Commands` as a parameter without having to move your own instance of `Commands`. Since this struct is composed entirely of references, we can easily get an owned instance of `Commands` by shortening the lifetime. ## Solution Add `Commands::reborrow`, `EntiyCommands::reborrow`, and `Deferred::reborrow`, which returns an owned version of themselves with a shorter lifetime. Remove unnecessary lifetimes from `EntityCommands`. The `'w` and `'s` lifetimes only have to be separate for `Commands` because it's used as a `SystemParam` -- this is not the case for `EntityCommands`. --- ## Changelog Added `Commands::reborrow`. This is useful if you have `&mut Commands` but need `Commands`. Also added `EntityCommands::reborrow` and `Deferred:reborrow` which serve the same purpose. ## Migration Guide The lifetimes for `EntityCommands` have been simplified. ```rust // Before (Bevy 0.12) struct MyStruct<'w, 's, 'a> { commands: EntityCommands<'w, 's, 'a>, } // After (Bevy 0.13) struct MyStruct<'a> { commands: EntityCommands<'a>, } ``` The method `EntityCommands::commands` now returns `Commands` rather than `&mut Commands`. ```rust // Before (Bevy 0.12) let commands = entity_commands.commands(); commands.spawn(...); // After (Bevy 0.13) let mut commands = entity_commands.commands(); commands.spawn(...); ``` |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |