Directive to exclude struct fields from being using'd #5708
mr0x13f
started this conversation in
Ideas/Requests
Replies: 1 comment
-
|
There is |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I ran into the situation where I had a struct that was
usingtwo other structs, which both have fields with the same name. I didn't really want to use#subtypeinstead, as I do want to pull some fields into the parent struct's namespace.A solution to this could be to add a new directive that is put in front of struct fields, which causes them to be excluded from being pulled into the namespace when
usingthe struct. Let's call it#hiddenfor now.Example:
Here the Entity struct pulls in fields from Trait_A and Trait_B. These traits themself have a
using'd pointer back to the parent Entity, which enables both 'up-casting' Entity to a trait and 'down-casting' a trait back to the Entity.Note that in this example I've put the directive on a field that's also
using, but non-usingfields could work the same.A 'hidden' field could of course still be accessed explicitly, i.e.:
entity.trait_a.entity.Without the new directive, the pointers to Entity would all need unique names, even though it's a field that doesn't really need to be pulled into the namespace anyway. Otherwise the traits can't be
using'd by Entity.Beta Was this translation helpful? Give feedback.
All reactions