Skip to content

[Merged by Bors] - bevy_reflect: Added get_boxed method to reflect_trait#4120

Closed
MrGVSV wants to merge 3 commits intobevyengine:mainfrom
MrGVSV:reflect-trait-box
Closed

[Merged by Bors] - bevy_reflect: Added get_boxed method to reflect_trait#4120
MrGVSV wants to merge 3 commits intobevyengine:mainfrom
MrGVSV:reflect-trait-box

Conversation

@MrGVSV
Copy link
Copy Markdown
Member

@MrGVSV MrGVSV commented Mar 6, 2022

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>.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Mar 6, 2022
@MrGVSV MrGVSV changed the title Added get_boxed method Added get_boxed method to reflect_trait Mar 6, 2022
@alice-i-cecile alice-i-cecile added A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Mar 6, 2022
Copy link
Copy Markdown
Member

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

Choose a reason for hiding this comment

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

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

@MrGVSV
Copy link
Copy Markdown
Member Author

MrGVSV commented Mar 6, 2022

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.

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.

Copy link
Copy Markdown
Member

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

Choose a reason for hiding this comment

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

LGTM! It's nice to slowly document reflection too :)

@MrGVSV MrGVSV changed the title Added get_boxed method to reflect_trait bevy_reflect: Added get_boxed method to reflect_trait Mar 28, 2022
@MrGVSV MrGVSV force-pushed the reflect-trait-box branch from ae69075 to 8793522 Compare May 13, 2022 04:07
Copy link
Copy Markdown
Contributor

@PROMETHIA-27 PROMETHIA-27 left a comment

Choose a reason for hiding this comment

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

LGTM!

@alice-i-cecile
Copy link
Copy Markdown
Member

bors r+

bors bot pushed a commit that referenced this pull request May 20, 2022
# 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]>
@bors bors bot changed the title bevy_reflect: Added get_boxed method to reflect_trait [Merged by Bors] - bevy_reflect: Added get_boxed method to reflect_trait May 20, 2022
@bors bors bot closed this May 20, 2022
james7132 pushed a commit to james7132/bevy that referenced this pull request Jun 7, 2022
…#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]>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants