-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
bevy_reflect: Add ReflectRef
/ReflectMut
/ReflectOwned
convenience casting methods
#15235
Merged
alice-i-cecile
merged 6 commits into
bevyengine:main
from
MrGVSV:mrgvsv/reflect/kind-conversions
Sep 23, 2024
Merged
bevy_reflect: Add ReflectRef
/ReflectMut
/ReflectOwned
convenience casting methods
#15235
alice-i-cecile
merged 6 commits into
bevyengine:main
from
MrGVSV:mrgvsv/reflect/kind-conversions
Sep 23, 2024
Conversation
This file contains 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
MrGVSV
added
C-Code-Quality
A section of code that is hard to understand or change
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
A-Reflection
Runtime information about types
D-Straightforward
Simple bug fixes and API improvements, docs, test and examples
S-Needs-Review
Needs reviewer attention (from anyone!) to move forward
labels
Sep 15, 2024
MrGVSV
force-pushed
the
mrgvsv/reflect/kind-conversions
branch
from
September 15, 2024 19:25
7303200
to
ba60c4c
Compare
alice-i-cecile
approved these changes
Sep 15, 2024
pablo-lua
approved these changes
Sep 22, 2024
pablo-lua
added
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
and removed
S-Needs-Review
Needs reviewer attention (from anyone!) to move forward
labels
Sep 22, 2024
@MrGVSV if this is merge-conflict-free tomorrow for the merge train I'll get this in :) |
MrGVSV
force-pushed
the
mrgvsv/reflect/kind-conversions
branch
from
September 23, 2024 03:57
b834b97
to
f6683d7
Compare
Co-authored-by: Pablo Reinhardt <126117294+pablo-lua@users.noreply.github.com>
MrGVSV
force-pushed
the
mrgvsv/reflect/kind-conversions
branch
from
September 23, 2024 04:27
f6683d7
to
66ae70f
Compare
This was referenced Oct 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Reflection
Runtime information about types
C-Code-Quality
A section of code that is hard to understand or change
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
D-Straightforward
Simple bug fixes and API improvements, docs, test and examples
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
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
TypeInfo
into 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 thereflect
module.Testing
You can test locally by running:
Showcase
Convenience methods for casting
ReflectRef
,ReflectMut
, andReflectOwned
into their respective variants has been added! This allows you to write cleaner code if you already know the kind of your reflected data: