bevy/crates/bevy_ecs/src
Giacomo Stevanato eff96e20a0
Add ReflectFromWorld and replace the FromWorld requirement on ReflectComponent and ReflectBundle with FromReflect (#9623)
# Objective

- `FromType<T>` for `ReflectComponent` and `ReflectBundle` currently
require `T: FromWorld` for two reasons:
    - they include a `from_world` method;
- they create dummy `T`s using `FromWorld` and then `apply` a `&dyn
Reflect` to it to simulate `FromReflect`.
- However `FromWorld`/`Default` may be difficult/weird/impractical to
implement, while `FromReflect` is easier and also more natural for the
job.
- See also
https://discord.com/channels/691052431525675048/1146022009554337792

## Solution

- Split `from_world` from `ReflectComponent` and `ReflectBundle` into
its own `ReflectFromWorld` struct.
- Replace the requirement on `FromWorld` in `ReflectComponent` and
`ReflectBundle` with `FromReflect`

---

## Changelog

- `ReflectComponent` and `ReflectBundle` no longer offer a `from_world`
method.
- `ReflectComponent` and `ReflectBundle`'s `FromType<T>` implementation
no longer requires `T: FromWorld`, but now requires `FromReflect`.
- `ReflectComponent::insert`, `ReflectComponent::apply_or_insert` and
`ReflectComponent::copy` now take an extra `&TypeRegistry` parameter.
- There is now a new `ReflectFromWorld` struct.

## Migration Guide

- Existing uses of `ReflectComponent::from_world` and
`ReflectBundle::from_world` will have to be changed to
`ReflectFromWorld::from_world`.
- Users of `#[reflect(Component)]` and `#[reflect(Bundle)]` will need to
also implement/derive `FromReflect`.
- Users of `#[reflect(Component)]` and `#[reflect(Bundle)]` may now want
to also add `FromWorld` to the list of reflected traits in case their
`FromReflect` implementation may fail.
- Users of `ReflectComponent` will now need to pass a `&TypeRegistry` to
its `insert`, `apply_or_insert` and `copy` methods.
2024-01-19 16:08:57 +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 Add ReflectFromWorld and replace the FromWorld requirement on ReflectComponent and ReflectBundle with FromReflect (#9623) 2024-01-19 16:08:57 +00:00
schedule Fix doc of [Schedules] to mention exclusion of current schedule. (#11360) 2024-01-15 19:13:13 +00:00
storage Minimize small allocations by dropping the tick Vecs from Resources (#11226) 2024-01-08 22:39:47 +00:00
system Dynamic queries and builder API (#9774) 2024-01-16 19:16:49 +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