-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
@@ -217,6 +218,133 @@ impl<T: FromReflect> FromReflect for Vec<T> { | |||
} | |||
} | |||
|
|||
impl<T: FromReflect> Array for VecDeque<T> { |
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 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);
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.
You'd probably need to specify the push
method to be used as well
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 Is it okay that we dumb all these structures down to their base types ( |
} | ||
|
||
impl<T: FromReflect> List for VecDeque<T> { | ||
fn push(&mut self, value: Box<dyn 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.
I wonder if List
should define a pop
method. Then we can use sorta use this structure as intended.
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.
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?
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 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.
Dumbing down is the "standard" way in my experience. The serde model also hints at that. |
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.
This LGTM; I won't block on either the macro-ification or the pop method (which I've pulled into a new issue).
bors r+ |
# Objective Fixes #5791 ## Solution Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.
Build failed: |
bors retry |
# Objective Fixes #5791 ## Solution Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.
Build failed (retrying...): |
# Objective Fixes #5791 ## Solution Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.
Build failed (retrying...): |
# Objective Fixes #5791 ## Solution Implemented all the required reflection traits for `VecDeque`, taking from `Vec`'s impls.
Build failed: |
This PR has been adopted as #6831. |
# 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>
# 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>
# 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>
Objective
Fixes #5791
Solution
Implemented all the required reflection traits for
VecDeque
, taking fromVec
's impls.