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

Implement Reflect for Result<T, E> as enum #13182

Merged

Conversation

TheNeikos
Copy link
Contributor

@TheNeikos TheNeikos commented May 2, 2024

Objective

Solution

  • Use the correct macro

Testing

  • Did you test these changes?

I tried it out locally, and it does what it says on the tin. Not sure how to test it in context of the crate?


Changelog

Changed

  • Result now uses ReflectKind::Enum rather than ReflectKind::Value, allowing for inspection of its constituents

Migration Guide

Result<T, E> has had its Reflect implementation changed to align it with Option<T> and its intended semantics: A carrier of either an Ok or Err value, and the ability to access it. To achieve this it is no longer a ReflectKind::Value but rather a ReflectKind::Enum and as such carries these changes with it:

For Result<T, E>

  • Both T and E no longer require to be Clone and now require to be FromReflect
  • <Result<T, E> as Reflect>::reflect_* now returns a ReflectKind::Enum, so any code that previously relied on it being a Value kind will have to be adapted.
  • Result<T, E> now implements Enum

Since the migration is highly dependent on the previous usage, no automatic upgrade path can be given.

Signed-off-by: Marcel Müller <neikos@neikos.email>
@TheNeikos TheNeikos force-pushed the feature/make_result_reflect_enum branch from 882db50 to 5a9f579 Compare May 2, 2024 14:35
@alice-i-cecile alice-i-cecile requested review from MrGVSV and soqb May 2, 2024 14:36
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Reflection Runtime information about types C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide labels May 2, 2024
Copy link
Contributor

github-actions bot commented May 2, 2024

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

@soqb
Copy link
Contributor

soqb commented May 2, 2024

thanks for getting round to this!

LGTM: implementation is correct and in the right place, and i am hugely on board with the semantic improvement.

this is a subtle breaking change (beyond the acknowledged ReflectKind migration) since it changes the bounds on T and E. they here require FromReflect (IIRC) where they didn't previously and no longer imply Clone. ergo, it does needs a little note in the PR description.

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.

LGTM!

I agree that a Migration Guide should be added, though.

@TheNeikos
Copy link
Contributor Author

@soqb @MrGVSV I added a Migration Guide to the PR Description. Not quite sure about the tone/addressee.

@MrGVSV
Copy link
Member

MrGVSV commented May 2, 2024

@soqb @MrGVSV I added a Migration Guide to the PR Description. Not quite sure about the tone/addressee.

That works for me! Thanks for adding it!

@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 2, 2024
@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 2, 2024
Merged via the queue into bevyengine:main with commit 6d25545 May 2, 2024
31 checks passed
@TheNeikos TheNeikos deleted the feature/make_result_reflect_enum branch May 2, 2024 19:40
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-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Bug An unexpected or incorrect behavior 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.

Result is reflected as a ReflectKind::Value, maybe could be an Enum instead?
4 participants