bevy/crates/bevy_reflect/src
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
..
enums deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
func Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
impls Fix PartialReflect::apply for maps, remove get_at/_mut from Map trait (#19802) 2025-06-25 15:42:01 +00:00
path Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
serde deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
array.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
attributes.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
error.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
fields.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
from_reflect.rs bevy_reflect: Apply #[deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17092) 2025-01-03 22:22:34 +00:00
generics.rs Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
kind.rs Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
lib.rs Fix PartialReflect::apply for maps, remove get_at/_mut from Map trait (#19802) 2025-06-25 15:42:01 +00:00
list.rs More uninlined_format_args fixes (#19396) 2025-05-28 02:35:18 +00:00
map.rs Fix PartialReflect::apply for maps, remove get_at/_mut from Map trait (#19802) 2025-06-25 15:42:01 +00:00
reflect.rs Fix PartialReflect::apply for maps, remove get_at/_mut from Map trait (#19802) 2025-06-25 15:42:01 +00:00
reflectable.rs bevy_reflect: Add Reflectable trait (#5772) 2024-09-18 00:36:41 +00:00
remote.rs Add no_std support to bevy_reflect (#16256) 2024-12-05 21:15:21 +00:00
set.rs Fix PartialReflect::apply for maps, remove get_at/_mut from Map trait (#19802) 2025-06-25 15:42:01 +00:00
std_traits.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
struct_trait.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
tuple_struct.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
tuple.rs Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
type_info_stack.rs Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
type_info.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00
type_path.rs Add no_std support to bevy_reflect (#16256) 2024-12-05 21:15:21 +00:00
type_registry.rs Add newlines before impl blocks (#19746) 2025-06-22 23:07:02 +00:00
utility.rs deny(missing_docs) for bevy_reflect (#19481) 2025-06-16 21:26:24 +00:00