-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
What problem does this solve or what need does it fill?
As discussed in #17886, some users find the new semantics and API of ChildOf frustrating and confusing (see #17247 for that change).
What solution would you like?
@cart and I think that we can improve the developer experience by swapping from a tupled struct to a named struct:
struct ChildOf{
parent: Entity
}This helps clarify what's going on by giving a name to the data that's being stored.
In order to do that, you'll need to:
- Modify the
Relationshipderive code (actually part of the Component macro) to work with named structs with a singleEntityfield. - Add a doc test for this.
- Refactor the
ChildOfcomponent and clean up all of the breakage. - Rename a few variables to
parentto make the code cleaner.
Take a peek at the Deref / DerefMut derives for tips on implementation, although you don't need to get fancy with attributes (see below).
What alternative(s) have you considered?
When this idea was initially proposed, Cart and I thought that marking a specific field as #[relationship_target] would be helpful to increase flexibility.
This isn't needed for the initial PR. Moreover, implementing Relationship::from in the derive for arbitrary structs which might contain data is not particularly feasible without adding quite a bit more complexity.
Don't bother with it for now! Advanced users can do a manual impl for now.
Additional context
I started tackling this today, hence the detailed notes. I'm not great at macros though, so I didn't finish it and I'm shouting into the void in the hopes that one of our lovely contributors finishes it. Bother me if you want to see my draft branch, but it's not particularly helpful beyond these notes.