bevy/crates/bevy_ecs/src
JoJoJet 9adc8cdaf6 Add Mut::reborrow (#7114)
# Objective

- In some cases, you need a `Mut<T>` pointer, but you only have a mutable reference to one. There is no easy way of converting `&'a mut Mut<'_, T>` -> `Mut<'a, T>` outside of the engine.

### Example (Before)

```rust
fn do_with_mut<T>(val: Mut<T>) { ... }

for x: Mut<T> in &mut query {
    // The function expects a `Mut<T>`, so `x` gets moved here.
    do_with_mut(x);
    // Error: use of moved value.
    do_a_thing(&x);
}
```

## Solution

- Add the function `reborrow`, which performs the mapping. This is analogous to `PtrMut::reborrow`.

### Example (After)

```rust
fn do_with_mut<T>(val: Mut<T>) { ... }

for x: Mut<T> in &mut query {
    // We reborrow `x`, so the original does not get moved.
    do_with_mut(x.reborrow());
    // Works fine.
    do_a_thing(&x);
}
```

---

## Changelog

- Added the method `reborrow` to `Mut`, `ResMut`, `NonSendMut`, and `MutUntyped`.
2023-01-09 22:20:10 +00:00
..
entity Fix various typos (#7096) 2023-01-06 00:43:30 +00:00
query Fix various typos (#7096) 2023-01-06 00:43:30 +00:00
schedule Panic on dropping NonSend in non-origin thread. (#6534) 2023-01-09 20:40:34 +00:00
storage Panic on dropping NonSend in non-origin thread. (#6534) 2023-01-09 20:40:34 +00:00
system Relax Sync bound on Local<T> as ExclusiveSystemParam (#7040) 2023-01-09 20:56:06 +00:00
world Implement SparseSetIndex for WorldId (#7125) 2023-01-09 21:43:27 +00:00
archetype.rs Fix various typos (#7096) 2023-01-06 00:43:30 +00:00
bundle.rs Extend EntityLocation with TableId and TableRow (#6681) 2023-01-02 21:25:04 +00:00
change_detection.rs Add Mut::reborrow (#7114) 2023-01-09 22:20:10 +00:00
component.rs Document options for !Sync types for Component and Resources (#6864) 2022-12-11 18:34:13 +00:00
event.rs Rework manual event iterator so we can actually name the type (#5735) 2022-12-25 00:39:27 +00:00
lib.rs Panic on dropping NonSend in non-origin thread. (#6534) 2023-01-09 20:40:34 +00:00
reflect.rs Enable Constructing ReflectComponent/Resource (#6257) 2022-10-17 14:01:50 +00:00