Create enumerating version of all_tuples#15936
Closed
mweatherley wants to merge 3 commits intobevyengine:mainfrom
Closed
Create enumerating version of all_tuples#15936mweatherley wants to merge 3 commits intobevyengine:mainfrom
all_tuples#15936mweatherley wants to merge 3 commits intobevyengine:mainfrom
Conversation
MrGVSV
approved these changes
Oct 15, 2024
Member
MrGVSV
left a comment
There was a problem hiding this comment.
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!)
Member
|
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. |
Contributor
|
I can try my hand at that again using this once this is merged and I'm feeling better. |
BenjaminBrienen
approved these changes
Oct 15, 2024
|
https://github.com/bevyengine/variadics_please has been created, please open a PR in that repo for the implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_tuplesthat can be used in these circumstances.Solution
Create
all_tuples_enumerated, a procedural macro which behaves much likeall_tuplesbut enumerates its output. Here is an example from the docs:The implementation for
StableInterpolateover tuples has been changed to use this pattern instead of doing manual enumeration. It also actually usesfake_variadicnow.Testing
Tested via macro expansion and compiling.