bevy/crates/bevy_reflect/src/impls
Alix Bott dd4479ed30
Fix PartialReflect::apply for maps, remove get_at/_mut from Map trait (#19802)
# Objective

- Fixes https://github.com/bevyengine/bevy/issues/14328
- `DynamicMap::drain` was broken (indices weren't cleared, causing a
panic when reading later)
- `PartialReflect::apply` was broken for maps and sets, because they
don't remove entries from the `self` map that aren't in the applied map.
- I discovered this bug when implementing MapEntities on a Component
containing a `HashMap<Entity, _>`. Because `apply` is used to reapply
the changes to the reflected map, the map ended up littered with a ton
of outdated entries.

## Solution

- Remove the separate `Vec` in `DynamicMap` and use the `HashTable`
directly, like it is in `DynamicSet`.
- Replace `MapIter` by `Box<dyn Iterator>` (like for `DynamicSet`), and
`Map::get_at` and `Map::get_at_mut` which are now unused.
- Now assume `DynamicMap` types are unordered and adjust documentation
accordingly.
- Fix documentation of `DynamicSet` (ordered -> unordered)
- Added `Map::retain` and `Set::retain`, and use them to remove excess
entries in `PartialReflect::apply` implementations.

## Testing

- Added `map::tests::apply` and `set::tests::apply` to validate
`<DynamicMap as PartialReflect>::apply` and `<DynamicSet as
PartialReflect>::apply`
2025-06-25 15:42:01 +00:00
..
alloc Fix PartialReflect::apply for maps, remove get_at/_mut from Map trait (#19802) 2025-06-25 15:42:01 +00:00
bevy_platform bevy_reflect: Split up the std module (#18939) 2025-05-26 19:10:47 +00:00
core Register ReflectSerialize for &'static str (#19680) 2025-06-16 22:09:15 +00:00
macros Fix PartialReflect::apply for maps, remove get_at/_mut from Map trait (#19802) 2025-06-25 15:42:01 +00:00
std bevy_reflect: Split up the std module (#18939) 2025-05-26 19:10:47 +00:00
foldhash.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
glam.rs bevy_reflect: Reflection-based cloning (#13432) 2025-03-11 06:02:59 +00:00
hashbrown.rs bevy_reflect: Split up the std module (#18939) 2025-05-26 19:10:47 +00:00
petgraph.rs Add PartialEq and Hash reflections for AnimationNodeIndex (#18718) 2025-04-04 16:35:12 +00:00
smallvec.rs Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
smol_str.rs bevy_reflect: Reflection-based cloning (#13432) 2025-03-11 06:02:59 +00:00
uuid.rs Add NonNilUuid support to bevy_reflect (#18604) 2025-05-04 08:22:57 +00:00
wgpu_types.rs bevy_reflect: Reflection-based cloning (#13432) 2025-03-11 06:02:59 +00:00