-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add reflect conversions #18757
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
base: main
Are you sure you want to change the base?
Add reflect conversions #18757
Conversation
d7f2a38
to
dd18684
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good so far! Just a few comments.
I'm planning to do a major rewrite to FromReflect
, and I think your changes here provide a really solid basis for that :)
a88df1d
to
e362bf9
Compare
Use if statements with explicit returns instead of one long if-else.
e362bf9
to
92a3361
Compare
I removed the example because changes to |
You don't need to do that, the dependencies workflow is not required and isn't blocking when merging |
f799ffb
to
92a3361
Compare
@MrGVSV are you still able to review this? The failing check is non-blocking. |
Yeah sorry I had it open a couple days ago but got a bit too busy. I'll try to re-review this week though! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your patience! Just a few comments/suggestions
@@ -27,14 +27,21 @@ pub(crate) fn impl_opaque(meta: &ReflectMeta) -> proc_macro2::TokenStream { | |||
let bevy_reflect_path = meta.bevy_reflect_path(); | |||
let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl(); | |||
let where_from_reflect_clause = WhereClauseOptions::new(meta).extend_where_clause(where_clause); | |||
|
|||
let exact_match = quote! { | |||
if let #FQOption::Some(value) = <dyn #bevy_reflect_path::PartialReflect>::try_downcast_ref::<#type_path #ty_generics>(reflect) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently had to fix this function to properly account for remote types in #19158. Might be worth adding that here or waiting for that PR to be merged.
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
} | |
else { | |
} else { |
let some_branch = if conversions.is_empty() { | ||
quote! { #value } | ||
} else { | ||
quote! { #(#conversions)else* else { #value } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Does #(#conversions else)* { #value }
work? Because not only would that remove the else
duplication, but might allow you to do away with some_branch
altogether.
} | ||
|
||
/// Deriving `Reflect` implements the relevant reflection traits. In this case, it implements the | ||
/// `Reflect` trait the `Struct` trait, and the `FromReflect` trait. `derive(Reflect)` assumes that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// `Reflect` trait the `Struct` trait, and the `FromReflect` trait. `derive(Reflect)` assumes that | |
/// `Reflect` trait, the `Struct` trait, and the `FromReflect` trait. `derive(Reflect)` assumes that |
Objective
FromReflect
traitSolution
FromReflect::from_reflect
Testing