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.
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: Unique
Reflect
#56bevy_reflect: Unique
Reflect
#56Changes from 5 commits
02f5777
e45293e
757173f
6dc6519
ab3c114
cd5e84a
bc7d6db
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Just so I am sure,
into_full
on a proxy type will always returnNone
, right?It only returns
Some
if thedyn PartialReflect
has an underlying typeT: 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.
Reading futher confirms that this is true.
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.
Yeah I think that's the idea. To convert a proxy, you'll still need to use
FromPartialReflect
like you do now withFromReflect
.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.
Do we still want to tie
PartialReflect
to a type name?I can think of a few situations where this isn't necessary/wanted.
a
andb
.The person can then create a
DynamicStruct
with the shared types and apply it to every value.PartialReflect
for non-rust values, e.g. a scripting language integration can implementPartialReflect
forLuaValue
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.
Mentioned this on Discord, but essentially
type_name
still has a use for deserialization.However, for Point 2 I think you could intentionally use a non-real type name and be fine. As long as you aren't hoping to deserialize it (unless you
#[reflect(Deserialize)]
), I think it should be okay.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.
One piece of information that this restructuring loses is that
reflect_ref
on a&dyn Reflect
will only contain&dyn Reflect
itself, no&dyn PartialReflect
.So you may have to call
into_full().unwrap()
in a few places where you know the value originates from a&dyn Reflect
.The alternative is duplicating the
ReflectRef
,ReflectMut
,Struct
,List
,Enum
etc. for variants that preserve&dyn Reflect
which is IMO not worth it.Just pointing it out.
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.
Regarding this, bevyengine/bevy#7207 does store
&dyn PartialReflect
in proxies and leavesPartialReflect: Any
. I think it will require a different vision onReflectRef
and proxies to complete the RFC and have a proper separation between proxy and canonical types.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 think this needs methods to turn it back into
PartialReflect
. At least until trait upcasting is stabilized.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.
As trait upcasting is not merged, it means I could give those methods the same name as the ones on
PartialReflect
?Such as:
fn as_partial_reflect(&self) -> &dyn PartialReflect
fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
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.
Hang on, it might actually be possible to call those methods of
PartialReflect
on anBox<dyn Reflect>
already.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.
it is possible. bevyengine/bevy#7207 uses this.
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.
Yeah I think it should definitely be a subtrait. Because then easily have access to all
PartialReflect
methods. Plus, it forces manual implementors to implement both, which might be necessary for certain reflect-based functionality (e.g. third-party crate assumptions).