-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Create enumerating version of all_tuples
#15936
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this would also be pretty useful for bevy_reflect
too (this is pretty much what we need to make impl_reflect_tuple!
compatible with all_tuples!
)
FYI I'm merging the simple fix in #15933 now, but I do think we should move fully to this. It does make me think we should pull all_tuples out into its own crate though: I'm not a fan of bevy_math relying on bevy_utils. |
I can try my hand at that again using this once this is merged and I'm feeling better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely :)
https://github.com/bevyengine/variadics_please has been created, please open a PR in that repo for the implementation. |
Objective
When writing macros that blanket-implement traits over tuples, it is often necessary to index into anonymous tuple struct fields. This turns out to be somewhat annoying, since it requires the indices to be passed sequentially in the macro invocation, which prevents the macro from being used with
all_tuples
.The goal here is to provide support for this pattern by introducing an enumerating version of
all_tuples
that can be used in these circumstances.Solution
Create
all_tuples_enumerated
, a procedural macro which behaves much likeall_tuples
but enumerates its output. Here is an example from the docs:The implementation for
StableInterpolate
over tuples has been changed to use this pattern instead of doing manual enumeration. It also actually usesfake_variadic
now.Testing
Tested via macro expansion and compiling.