bevy/crates/bevy_hierarchy/src
Joseph 7d69d3195f
refactor: Simplify lifetimes for Commands and related types (#11445)
# 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(...);
```
2024-01-22 15:35:42 +00:00
..
components Inline trivial methods in bevy_hierarchy (#11332) 2024-01-13 22:20:50 +00:00
child_builder.rs refactor: Simplify lifetimes for Commands and related types (#11445) 2024-01-22 15:35:42 +00:00
events.rs Require #[derive(Event)] on all Events (#7086) 2023-06-06 14:44:32 +00:00
hierarchy.rs refactor: Simplify lifetimes for Commands and related types (#11445) 2024-01-22 15:35:42 +00:00
lib.rs Add bevy_hierarchy Crate and plugin documentation (#10951) 2024-01-02 19:40:14 +00:00
query_extension.rs Rename Q type parameter to D when referring to WorldQueryData (#10782) 2023-12-13 18:50:46 +00:00
valid_parent_check_plugin.rs Make bevy_app and reflect opt-out for bevy_hierarchy. (#10721) 2023-11-25 03:05:38 +00:00