bevy_reflect: Add ReflectRef/ReflectMut/ReflectOwned convenience casting methods#15235
Merged
alice-i-cecile merged 6 commits intobevyengine:mainfrom Sep 23, 2024
Merged
Conversation
7303200 to
ba60c4c
Compare
alice-i-cecile
approved these changes
Sep 15, 2024
pablo-lua
approved these changes
Sep 22, 2024
Member
|
@MrGVSV if this is merge-conflict-free tomorrow for the merge train I'll get this in :) |
b834b97 to
f6683d7
Compare
Co-authored-by: Pablo Reinhardt <126117294+pablo-lua@users.noreply.github.com>
f6683d7 to
66ae70f
Compare
This was referenced Oct 29, 2024
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
#13320 added convenience methods for casting a
TypeInfointo its respective variant:This is especially helpful when you have already verified a type is a certain kind via
ReflectRef,ReflectMut,ReflectOwned, orReflectKind.As mentioned in that PR, though, it would be useful to add similar convenience methods to those types as well.
Solution
Added convenience casting methods to
ReflectRef,ReflectMut, andReflectOwned.With these methods, I was able to reduce our nesting in certain places throughout the crate.
Additionally, I took this opportunity to move these types (and
ReflectKind) to their own module to help clean up thereflectmodule.Testing
You can test locally by running:
Showcase
Convenience methods for casting
ReflectRef,ReflectMut, andReflectOwnedinto their respective variants has been added! This allows you to write cleaner code if you already know the kind of your reflected data: