Skip to content
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

Finish the work on try_apply #12646

Merged
merged 7 commits into from
May 8, 2024
Merged

Conversation

Brezak
Copy link
Contributor

@Brezak Brezak commented Mar 22, 2024

Objective

Finish the try_apply implementation started in #6770 by @feyokorenhof.
Supersedes and closes #6770. Closes #6182

Solution

Add try_apply to Reflect and implement it in all the places that implement Reflect.


Changelog

Added try_apply to Reflect.

@matiqo15 matiqo15 added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types labels Mar 22, 2024
@Brezak
Copy link
Contributor Author

Brezak commented Mar 22, 2024

Current TODO:

  • One last cleanup pass over the try_apply implementations.
  • Figure out how to properly handle errors
    • Figure out which fields of the enum can be turned into static strings.
    • Maybe switch to a opaque struct with a kinds function.
  • Write tests using try_apply (apply defaults to using try_apply but we should test if the proper errors are returned).

@Brezak Brezak force-pushed the try_apply branch 4 times, most recently from 8c712a6 to 4e255ee Compare March 23, 2024 14:16
@Brezak Brezak marked this pull request as ready for review March 23, 2024 14:58
@Brezak
Copy link
Contributor Author

Brezak commented Mar 23, 2024

The code is mostly finished. I'm just not confident about ApplyError. Strictly speaking its error messages are more correct than what the original panics would report. It's errors specify both types when there's a mismatch and will specify what kind of structure we're working with for all reflect types. On the other hand they more often fail to mention what field our operation failed at. My biggest concern is interaction with FromReflect in enum variant construction where we have to guess why exactly from_reflect failed.

@james7132 james7132 requested review from MrGVSV and soqb March 23, 2024 20:54
Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a few comments/suggestions.

I also added suggestions to move some of the macro code to use fully-qualified syntax (hopefully with the bulk-apply for PR suggestions, that can take some of the work off your plate).

crates/bevy_reflect/src/reflect.rs Show resolved Hide resolved
crates/bevy_reflect/src/reflect.rs Outdated Show resolved Hide resolved
crates/bevy_reflect/src/reflect.rs Outdated Show resolved Hide resolved
crates/bevy_reflect/src/reflect.rs Outdated Show resolved Hide resolved
crates/bevy_reflect/src/reflect.rs Outdated Show resolved Hide resolved
crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs Outdated Show resolved Hide resolved
crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs Outdated Show resolved Hide resolved
crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs Outdated Show resolved Hide resolved
crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs Outdated Show resolved Hide resolved
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
@Brezak Brezak force-pushed the try_apply branch 7 times, most recently from 04d06a7 to 8c213ff Compare May 6, 2024 16:01
@Brezak Brezak requested a review from MrGVSV May 6, 2024 16:01
Copy link
Contributor

@soqb soqb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this LGTM. just two little things before i approve.

crates/bevy_reflect/src/utility.rs Outdated Show resolved Hide resolved
crates/bevy_reflect/src/utility.rs Outdated Show resolved Hide resolved
crates/bevy_utils/README.md Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label May 8, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 8, 2024
Merged via the queue into bevyengine:main with commit 9c4ac7c May 8, 2024
28 checks passed
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-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-panicking Version of Reflect.apply()
6 participants