bevy_reflect: Optional generic info#24383
Draft
MrGVSV wants to merge 1 commit into
Draft
Conversation
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
Resolves #24379
Solution
This PR does makes it so that
TypeParamInfoandConstParamInfo(and thus,GenericInfo) capture type information optionally. This allows us to still capture some details about a generic type even when#[reflect(type_path = false)]is used.It essentially allows us to capture the following details in every case:
T)const N: usize = 10orT: Clone = String). Note that the type parameter case still needs to implementTypePath, but the type is known so we don't have to really worry about it in the impl's where clause.And so the optional information becomes:
TypePath). We can change this if desired. I only didn't to prepare for a potential future where more types support being const parameters.Note
This PR is open for debate. While it provides useful generic details to devs when a type opt-out of the
TypePathauto-derive, it does come at the cost of wrapping all generic type info surfaces inOption. This means a generally worse developer experience in the most common cases in exchange for a small benefit in the least common cases.I'd especially love to hear if anyone has experience with generic types that need to opt out of the
TypePathderive and where this kind of type info would be useful.Testing
Added some unit tests!
Showcase
Reflected types marked with
#[reflect(type_path = false)]now capture basic generic information.