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 1 commit
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.
Won't that prevent
Reflect
from working for non-rust types like in case of scripting?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.
Could you elaborate. How do you use a non-rust type in rust? Wouldn't it need a conversion at one point?
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.
The idea would be that you have for example a
PyObject
which is how any python object is internally represented and then it'sReflect
implementation would present a different type depending on the type thePyObject
has on the python side. For example fora
PyObject
holding aFoo
would present the fieldsa
andb
, while aPyObject
holding aBar
would present the fieldsc
andd
and aPyObject
holding an array would present itself as an array throughReflect
.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.
But this only exists on the Python side, right? What would this map to in Rust currently if there's no matching struct? A
DynamicStruct
?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 doesn't need to map to a rust type I think.
downcast
could return None for any type you attempt to downcast to.type_name
would give the python name. It shouldn't map toDynamicStruct
as that would lose the python type.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.
That would work, but it would have the exact same issue as what the
Dynamic*
types have right now in that the downcasted type doesn't match the semantic type that determines the layout which.reflect()
gives.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 I get the issue here. What about the proposition of moving
reflect_ref
andreflect_mut
to their own trait independent fromReflect
(call it theBavy
trait) and also move all theReflect
subtraits toBavy
? You could then implementBavy
forPyObject
(or a wrapper type, per orphan rule). Maybe also move thesidecast
proposition and implementBavy
forReflectProxy
?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 would rather go the opposite way and move all methods except
reflect_ref
andreflect_mut
into separate traits as not every type may have an implementation for them andreflect_ref
andreflect_mut
are the core reflection api.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.
@bjorn3 I think this is a good idea. Maybe I could revise this RFC to have a
UniqueReflect
vsReflect
?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.
why would you want to reuse Reflect as a trait for this as opposed to writing specific code for Python? what's the use case? I thought Reflect as a trait is supposed to model how you can represent data in Rust, not in any language ever.
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.
How would this work? For example, if I have the following code:
Is it doing the same thing as
FromReflect
does currently where we require ignored fields beDefault
?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 don't think this adds complexity so much as points it out; which makes it easier to deal with that complexity by modelling it more accurately.
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'd argue that the actual biggest use-case for them is deserialization. Since we can't guarantee that all types implement
FromReflect
we're forced to return aDynamic***
.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.
From what I gather, it really just encapsulates what
FromReflect
did. I imagine we'll have to do a similar thing. The tricky part is handling stuff beyond justDefault
, such asFromWorld
.