[Merged by Bors] - bevy_reflect: Added get_boxed method to reflect_trait#4120
[Merged by Bors] - bevy_reflect: Added get_boxed method to reflect_trait#4120MrGVSV wants to merge 3 commits intobevyengine:mainfrom
get_boxed method to reflect_trait#4120Conversation
There was a problem hiding this comment.
Implementation looks good, and this is clear and useful functionality. I would really like docs on this (and get_func and get_mut_funct), but I'm not immediately sure where they should go. Sticking them on the macro is waaay deep in the internals, and sticking them on the generated code is a bit odd.
I think that I would like it on both: it looks like we're generating a ReflectFoo type when this is used, and that should have proper docs.
Could you please add:
- basic docs to reflect_trait function.
- generated doc strings for the generated trait
- generated doc strings for the methods
Haha I was actually going to ask about this. I think it makes sense to put them in the generated code. In that case it shows up in intellisense and other editor tools. |
alice-i-cecile
left a comment
There was a problem hiding this comment.
LGTM! It's nice to slowly document reflection too :)
get_boxed method to reflect_traitget_boxed method to reflect_trait
Co-authored-by: Alice Cecile <[email protected]>
|
bors r+ |
# Objective Allow `Box<dyn Reflect>` to be converted into a `Box<dyn MyTrait>` using the `#[reflect_trait]` macro. The other methods `get` and `get_mut` only provide a reference to the reflected object. ## Solution Add a `get_boxed` method to the `Reflect***` struct generated by the `#[reflect_trait]` macro. This method takes in a `Box<dyn Reflect>` and returns a `Box<dyn MyTrait>`. Co-authored-by: MrGVSV <[email protected]>
get_boxed method to reflect_traitget_boxed method to reflect_trait
…#4120) # Objective Allow `Box<dyn Reflect>` to be converted into a `Box<dyn MyTrait>` using the `#[reflect_trait]` macro. The other methods `get` and `get_mut` only provide a reference to the reflected object. ## Solution Add a `get_boxed` method to the `Reflect***` struct generated by the `#[reflect_trait]` macro. This method takes in a `Box<dyn Reflect>` and returns a `Box<dyn MyTrait>`. Co-authored-by: MrGVSV <[email protected]>
…#4120) # Objective Allow `Box<dyn Reflect>` to be converted into a `Box<dyn MyTrait>` using the `#[reflect_trait]` macro. The other methods `get` and `get_mut` only provide a reference to the reflected object. ## Solution Add a `get_boxed` method to the `Reflect***` struct generated by the `#[reflect_trait]` macro. This method takes in a `Box<dyn Reflect>` and returns a `Box<dyn MyTrait>`. Co-authored-by: MrGVSV <[email protected]>
Objective
Allow
Box<dyn Reflect>to be converted into aBox<dyn MyTrait>using the#[reflect_trait]macro. The other methodsgetandget_mutonly provide a reference to the reflected object.Solution
Add a
get_boxedmethod to theReflect***struct generated by the#[reflect_trait]macro. This method takes in aBox<dyn Reflect>and returns aBox<dyn MyTrait>.