Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge _Reflect and _WithRegistry commands #9680

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nicopap
Copy link
Contributor

@nicopap nicopap commented Sep 3, 2023

Objective

While code was already effectively deduplicated, this further deduplicates it, by removing InsertReflect and RemoveReflect, since they were just specialized version of their _WithRegistry counterparts.

Solution

  • Add ReadTypeRegistry trait, implemented for AsRef<TypeRegistry> and AppTypeRegistry
  • Add default impl for ReflectCommandExt insert_reflect and remove_reflect methods
  • Remove InsertReflect and RemoveReflect in favor of InsertReflectWithRegistry<AppTypeRegistry> and equivalent.

@nicopap nicopap added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change A-Reflection Runtime information about types labels Sep 3, 2023
crates/bevy_ecs/src/reflect/entity_commands.rs Outdated Show resolved Hide resolved
crates/bevy_ecs/src/reflect/entity_commands.rs Outdated Show resolved Hide resolved
crates/bevy_ecs/src/reflect/entity_commands.rs Outdated Show resolved Hide resolved
crates/bevy_ecs/src/reflect/entity_commands.rs Outdated Show resolved Hide resolved
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to collapse these :) The AsDeref + ReadTypeRegistry gymnastics don't seem particularly worth it to me without more context, but I won't block over that.

@nicopap
Copy link
Contributor Author

nicopap commented Sep 10, 2023

I would have preferred a solution where we implement AsRef<TypeRegistry> or Deref<Target=TypeRegistry> for AppTypeRegistry, but because of the lock guard from RwLock::read, it's not possible to do. I've had several attempts, but finally concluded it wasn't possible. So I created the ReadTypeRegistry trait. The GAT lifetime is because of this.

@SkiFire13
Copy link
Contributor

Note that TypeRegistry itself does not implement AsRef<TypeRegistry> (in general AsRef<T> is not automatically implemented for T, but Borrow<T> is)

While code was already effectively deduplicated, this further
deduplicates it, by removing InsertReflect and RemoveReflect, since they
were just specialized version of their _WithRegistry counterparts.

- Add ReadTypeRegistry trait, implemented for AsRef<TypeRegistry>
  and AppTypeRegistry
- Add default impl for ReflectCommandExt insert_reflect and
  remove_reflect methods
- Remove InsertReflect and RemoveReflect in favor of
  InsertReflectWithRegistry<AppTypeRegistry> and equivalent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events A-Reflection Runtime information about types C-Code-Quality A section of code that is hard to understand or change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants