bevy/crates/bevy_ecs/src/world
TheBigCheese 865041de74
Add an Entry api to EntityWorldMut. (#10650)
# Objective

Adds `.entry` to `EntityWorldMut` with `Entry`, `OccupiedEntry` and
`VacantEntry` for easier in-situ modification, based on `HashMap.entry`.

Fixes #10635

## Solution

This adds the `entry` method to `EntityWorldMut` which returns an
`Entry`. This is an enum of `OccupiedEntry` and `VacantEntry` and has
the methods `and_modify`, `insert_entry`, `or_insert`, `or_insert_with`
and `or_default`. The only difference between `OccupiedEntry` and
`VacantEntry` is the type, they are both a mutable reference to the
`EntityWorldMut` and a marker for the component type, `HashMap` also
stores things to make it quicker to access the data in `OccupiedEntry`
but I wasn't sure if we had anything it would be logical to store to
make accessing/modifying the component faster? As such, the differences
are that `OccupiedEntry` assumes the entity has the component (because
nothing else can have an `EntityWorldMut` so it can't be changed outside
the entry api) and has different methods.

All the methods are based very closely off `hashbrown::HashMap` (because
its easier to read the source of) with a couple of quirks like
`OccupiedEntry.insert` doesn't return the old value because we don't
appear to have an api for mem::replacing components.

---

## Changelog

- Added a new function `EntityWorldMut.entry` which returns an `Entry`,
allowing easier in-situ modification of a component.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Pascal Hertleif <killercup@gmail.com>
2023-11-21 01:26:06 +00:00
..
entity_ref.rs Add an Entry api to EntityWorldMut. (#10650) 2023-11-21 01:26:06 +00:00
error.rs Replace all labels with interned labels (#7762) 2023-10-25 21:39:23 +00:00
identifier.rs Improve safety for the multi-threaded executor using UnsafeWorldCell (#8292) 2023-05-29 15:22:10 +00:00
mod.rs Add an Entry api to EntityWorldMut. (#10650) 2023-11-21 01:26:06 +00:00
spawn_batch.rs Fix some nightly warnings (#9672) 2023-09-02 18:35:06 +00:00
unsafe_world_cell.rs Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
world_cell.rs Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00