bevy/crates/bevy_ecs/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
..
entity Unified identifer for entities & relations (#9797) 2024-01-13 01:09:32 +00:00
identifier Unified identifer for entities & relations (#9797) 2024-01-13 01:09:32 +00:00
query Dynamic queries and builder API (#9774) 2024-01-16 19:16:49 +00:00
reflect refactor: Simplify lifetimes for Commands and related types (#11445) 2024-01-22 15:35:42 +00:00
schedule Optional state (#11417) 2024-01-19 21:38:04 +00:00
storage Double the capacity when BlobVec is full (#11167) 2024-01-22 15:05:34 +00:00
system refactor: Simplify lifetimes for Commands and related types (#11445) 2024-01-22 15:35:42 +00:00
world Get Change Tick methods for Resources (#11404) 2024-01-18 15:58:13 +00:00
archetype.rs Rename ArchetypeEntity::entity into ArchetypeEntity::id (#11118) 2024-01-01 16:12:24 +00:00
bundle.rs Allow #[derive(Bundle)] on tuple structs (take 3) (#10561) 2023-11-21 01:09:16 +00:00
change_detection.rs Simplify conditions (#11316) 2024-01-13 13:22:17 +00:00
component.rs Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
event.rs Explain EventWriter limits concurrency (#11063) 2023-12-24 17:45:21 +00:00
lib.rs Add ReflectFromWorld and replace the FromWorld requirement on ReflectComponent and ReflectBundle with FromReflect (#9623) 2024-01-19 16:08:57 +00:00
removal_detection.rs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00