Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

FromReflect Ergonomics#59

Closed
MrGVSV wants to merge 9 commits into
bevyengine:mainfrom
MrGVSV:main
Closed

FromReflect Ergonomics#59
MrGVSV wants to merge 9 commits into
bevyengine:mainfrom
MrGVSV:main

Conversation

@MrGVSV

@MrGVSV MrGVSV commented Jul 2, 2022

Copy link
Copy Markdown
Member

RENDERED

Derive FromReflect by default when deriving Reflect, add ReflectFromReflect type data, and make ReflectDeserializer easier to use.

@PROMETHIA-27 PROMETHIA-27 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Love this! I am fully behind and have wanted every feature here for a while.

Comment thread rfcs/59-from_reflect_ergonomics.md Outdated

## Unresolved questions

- Should `ReflectFromReflect` be replaced by a method on `TypeRegistration`, such as `TypeRegistration::construct`?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think so, but I wouldn't be opposed to adding construct() as a helper function which wraps over ReflectFromReflect.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah I agree that we should keep RFR. I decided to leave out the Future Possibilities section, but in it I originally described adding a ReflectFromWorldReflect type data to support a proposed FromWorldReflect trait. And my thought was that this would pair nicely with RFR without needing to create another method on TypeRegistration. (Left out that section because it seemed a bit off-topic, though, haha.)

And also, by keeping RFR we keep open the possibility of cloning and storing the type data outside the registry if needed.

Comment thread rfcs/59-from_reflect_ergonomics.md
Comment thread rfcs/59-from_reflect_ergonomics.md
Comment thread rfcs/59-from_reflect_ergonomics.md Outdated
Comment thread rfcs/59-from_reflect_ergonomics.md Outdated

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please try to split your lines at the sentence / clause level; it makes reviewing and suggestions much more pleasant :)

@Nilirad Nilirad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Have you considered using the “static type” instead of “real type”? It seems to be a direct translation from dynamic vs static typing.

Comment thread rfcs/59-from_reflect_ergonomics.md Outdated
Comment thread rfcs/59-from_reflect_ergonomics.md Outdated
Comment thread rfcs/59-from_reflect_ergonomics.md Outdated
@MrGVSV

MrGVSV commented Jul 4, 2022

Copy link
Copy Markdown
Member Author

Have you considered using the “static type” instead of “real type”? It seems to be a direct translation from dynamic vs static typing.

I did, but chose not to use it. My reasoning was that "static" feels like we should know the exact type at compile time. However, a dyn Reflect could still be a "real type", even though it isn't statically known.

@MrGVSV

MrGVSV commented Jul 4, 2022

Copy link
Copy Markdown
Member Author

Please try to split your lines at the sentence / clause level; it makes reviewing and suggestions much more pleasant :)

Okay I split bascially every sentence across multiple lines (where I could). Typora hates me now lol, but hopefully that's more readable/reviewable 🙂

@raffaeleragni

Copy link
Copy Markdown

Any update on this? I am trying to deserialize some bevy basic types (eg Transform) but can't rewire the type from DynamicStruct, because it doesn't have ReflectFromReflect.

@MrGVSV

MrGVSV commented May 31, 2023

Copy link
Copy Markdown
Member Author

Any update on this?

Unfortunately, there hasn't been much progress. While @cart has suggested more of an openness to merging FromReflect into the derive for Reflect, I haven't taken the time to update the RFC.

One reason I haven't updated it is because after coding the initial implementation in bevyengine/bevy#6056, I just found the RFC to be overkill. The actual changes are only a few hundred lines and most of it is cleanup. On top of that, ReflectFromReflect, which was part of this RFC, got merged on its own pretty easily.

So I could update this, but I may just close it out in favor of just using bevyengine/bevy#6056 to respond to any feedback. I'll probably rebase and update that PR relatively soon. Thoughts?


I am trying to deserialize some bevy basic types (eg Transform) but can't rewire the type from DynamicStruct, because it doesn't have ReflectFromReflect.

If you want to make a PR adding in a ReflectFromReflect registration, I'm sure that will be easily accepted (basically a four line change to cover both Transform and GlobalTransform).

In the meantime, however, you can just manually register it for all your known types:

app.register_type_data::<Transform, ReflectFromReflect>();

@raffaeleragni

Copy link
Copy Markdown

Didn't know there was a workaround, that's actually great, thanks.

@MrGVSV

MrGVSV commented Jun 4, 2023

Copy link
Copy Markdown
Member Author

Closing this out. See bevyengine/bevy#6056 (comment) for details.

@MrGVSV MrGVSV closed this Jun 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants