bevy_reflect: Access Type from dyn PartialReflect#24585
Open
MrGVSV wants to merge 4 commits into
Open
Conversation
This time for `DynamicTyped`
Contributor
|
It looks like your PR is a breaking change, but you didn't provide a migration guide. Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes. |
Member
|
I quite like your choice of names, and the functionality is useful here :) I think we can stabilize those names. |
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
The
Typetype was added in #14838 and acts like aTypeIdthat retains info of itsTypePath. However, this was somewhat tedious to retrieve on a reflected value.If you have a
dyn Reflect, you have to do this:And if all you have is a
dyn PartialReflect, then you have to do this:And on top of that, this means that we can never get the
Typeof a dynamic type at runtime since dynamic types do not have a correspondingTypeInfo.Compare this to
TypePath, which viaDynamicTypePath(a supertrait onPartialReflect), we can do this to get the type path of adyn PartialReflect:And that will work for both dynamic and concrete types.
This should be true for
Typeas well.Solution
This PR adds two new methods:
PartialReflect::comptime_typePartialReflect::runtime_typeI chose the
comptimeandruntimeprefixes because I wanted words that weren't as overloaded. I could have also gone withconcreteanddynamic, but my worry was thatdynamic_typewould be too easily confused with our concept of a "dynamic type". And it's actually the opposite: this doesn't return theTypeof the underlying dynamic type, but theTypeof the concrete type the underlying dynamic type is proxying.I'm open to feedback on the names!
I did try to unify the terminology to some extent by also making the following changes:
PartialReflect::get_represented_type_info->PartialReflect::runtime_type_infoDynamicTyped::reflect_type_info->DynamicTyped::comptime_type_infoTodo
Testing
Added unit tests for remote types.
Showcase
TODO