Skip to content
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

Add reflection support for VecDeque #5792

Closed
wants to merge 1 commit into from

Conversation

ItsDoot
Copy link
Contributor

@ItsDoot ItsDoot commented Aug 25, 2022

Objective

Fixes #5791

Solution

Implemented all the required reflection traits for VecDeque, taking from Vec's impls.

@@ -217,6 +218,133 @@ impl<T: FromReflect> FromReflect for Vec<T> {
}
}

impl<T: FromReflect> Array for VecDeque<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this implementation is also exactly the same as the Vec<T> impl (minus the Vec/VecDeque type haha).
Since they're basically the exact same, imo, it's worth making a macro therefore we can DRY the code up a bit.
e.g.

macro_rules! vec_like_reflection { .. }

vec_like_reflection!(Vec);
vec_like_reflection!(VecDeque);

Copy link
Member

Choose a reason for hiding this comment

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

You'd probably need to specify the push method to be used as well

@mockersf mockersf added the A-Reflection Runtime information about types label Aug 25, 2022
@MrGVSV
Copy link
Member

MrGVSV commented Aug 25, 2022

Hm, this is an interesting one because it's a slightly different data structure. We sorta lose its usefulness (the queue properties) when reflecting, and we can only really get it back after casting back to its original type (or providing TypeData to use it).

Is it okay that we dumb all these structures down to their base types (List/Map)? Should they instead be considered Value types like HashSet? I think this is fine, but I'd like to hear if anyone has any other thoughts on this matter.

}

impl<T: FromReflect> List for VecDeque<T> {
fn push(&mut self, value: Box<dyn Reflect>) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if List should define a pop method. Then we can use sorta use this structure as intended.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, a pop() method would make sense.
Granted though, a normal pop() on a Vec and a VecDeque is basically the same performance wise.
The difference is lies within a pop_front or push_front implementation.
Granted, I don't know if that means we also want to add a Deque trait for example.
Since then the question is, when does adding more and more traits become to cumbersome?

Copy link
Member

@MrGVSV MrGVSV Aug 25, 2022

Choose a reason for hiding this comment

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

Yeah that's what I was getting at in my other comment. I don't think it's going to be beneficial to add a new trait for each data structure type. That can probably be served somehow via TypeData.

But a pop method at least let's us handle lists, queues, and stacks in a general way.

@alice-i-cecile alice-i-cecile added the C-Usability A targeted quality-of-life change that makes Bevy easier to use label Aug 25, 2022
@djeedai
Copy link
Contributor

djeedai commented Aug 26, 2022

Is it okay that we dumb all these structures down to their base types (List/Map)? Should they instead be considered Value types like HashSet? I think this is fine, but I'd like to hear if anyone has any other thoughts on this matter.

Dumbing down is the "standard" way in my experience. The serde model also hints at that.

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

This LGTM; I won't block on either the macro-ification or the pop method (which I've pulled into a new issue).

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Sep 7, 2022
@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Sep 7, 2022
# Objective

Fixes #5791

## Solution

Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.
@bors
Copy link
Contributor

bors bot commented Sep 7, 2022

Build failed:

@alice-i-cecile
Copy link
Member

bors retry

bors bot pushed a commit that referenced this pull request Sep 19, 2022
# Objective

Fixes #5791

## Solution

Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.
@bors
Copy link
Contributor

bors bot commented Sep 19, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Sep 19, 2022
# Objective

Fixes #5791

## Solution

Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.
@bors
Copy link
Contributor

bors bot commented Sep 19, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Sep 19, 2022
# Objective

Fixes #5791

## Solution

Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.
@bors
Copy link
Contributor

bors bot commented Sep 19, 2022

Build failed:

@mockersf
Copy link
Member

@ItsDoot merging this PR fails because of missing implementations of drain and pop which were added in #5728 and #5797.

Could you add those? thanks!

@cart cart removed the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Sep 27, 2022
@rparrett rparrett added the S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! label Nov 7, 2022
@james7132
Copy link
Member

This PR has been adopted as #6831.

@james7132 james7132 closed this Dec 3, 2022
bors bot pushed a commit that referenced this pull request Dec 11, 2022
# Objective
This is an adoption of #5792. Fixes #5791.

## Solution
Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.

---

## Changelog
Added: `std::collections::VecDeque` now implements `Reflect` and all relevant traits.

Co-authored-by: james7132 <contact@jamessliu.com>
alradish pushed a commit to alradish/bevy that referenced this pull request Jan 22, 2023
# Objective
This is an adoption of bevyengine#5792. Fixes bevyengine#5791.

## Solution
Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.

---

## Changelog
Added: `std::collections::VecDeque` now implements `Reflect` and all relevant traits.

Co-authored-by: james7132 <contact@jamessliu.com>
ItsDoot added a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective
This is an adoption of bevyengine#5792. Fixes bevyengine#5791.

## Solution
Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.

---

## Changelog
Added: `std::collections::VecDeque` now implements `Reflect` and all relevant traits.

Co-authored-by: james7132 <contact@jamessliu.com>
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 S-Adopt-Me The original PR author has no intent to complete this work. Pick me up!
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Missing Reflect impl for VecDeque
9 participants