-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: support map insertion #3701
Conversation
May I please have an update on the status of this merge? It's important for any scenes with components with Hashmaps. |
So, this needs another review before it can be considered for merge. If you're comfortable with the code base (and especially if you've tested it out), feel free to leave one. Good-faith community approvals count on Bevy :) |
@@ -166,7 +166,7 @@ impl<T: FromReflect> FromReflect for Vec<T> { | |||
} | |||
} | |||
|
|||
impl<K: Reflect + Eq + Hash, V: Reflect> Map for HashMap<K, V> { | |||
impl<K: FromReflect + Eq + Hash, V: FromReflect> Map for HashMap<K, V> { |
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 imagine this could be a breaking change. Maybe add a Migration Guide
section on the PR comment explaining that key and value types now have a FromReflect
bound instead of Reflect
?
let value = value.take::<V>().unwrap_or_else(|value| { | ||
V::from_reflect(&*value).unwrap_or_else(|| { | ||
panic!( | ||
"Attempted to push invalid value of 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.
Nit: Why is this push
and not insert
?
"Attempted to push invalid value of type {}.", | |
"Attempted to insert invalid value of type {}.", |
/// Applies the elements of `b` to the corresponding elements of `a`. | ||
/// | ||
/// If a key from `b` does not exist in `a`, the value is cloned and inserted. | ||
/// | ||
/// # Panics | ||
/// | ||
/// This function panics if `b` is not a map. |
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.
Nit: Maybe reiterate that these two parameters are maps (as opposed to an iterator of tuples or something else).
/// Applies the elements of `b` to the corresponding elements of `a`. | |
/// | |
/// If a key from `b` does not exist in `a`, the value is cloned and inserted. | |
/// | |
/// # Panics | |
/// | |
/// This function panics if `b` is not a map. | |
/// Applies the elements of reflected map `b` to the corresponding elements of map `a`. | |
/// | |
/// If a key from `b` does not exist in `a`, the value is cloned and inserted. | |
/// | |
/// # Panics | |
/// | |
/// This function panics if `b` is not a reflected map. |
Feel free to change my wording if preferred.
# Objective This is a rebase of #3701 which is currently scheduled for 0.8 but is marked for adoption. > Fixes #3609 ## Solution > - add an `insert_boxed()` method on the `Map` trait > - implement it for `HashMap` using a new `FromReflect` generic bound > - add a `map_apply()` helper method to implement `Map::apply()`, that inserts new values instead of ignoring them --- ## Changelog TODO Co-authored-by: james7132 <contact@jamessliu.com>
Adopted and finished in #5173 |
# Objective This is a rebase of bevyengine#3701 which is currently scheduled for 0.8 but is marked for adoption. > Fixes bevyengine#3609 ## Solution > - add an `insert_boxed()` method on the `Map` trait > - implement it for `HashMap` using a new `FromReflect` generic bound > - add a `map_apply()` helper method to implement `Map::apply()`, that inserts new values instead of ignoring them --- ## Changelog TODO Co-authored-by: james7132 <contact@jamessliu.com>
# Objective This is a rebase of bevyengine#3701 which is currently scheduled for 0.8 but is marked for adoption. > Fixes bevyengine#3609 ## Solution > - add an `insert_boxed()` method on the `Map` trait > - implement it for `HashMap` using a new `FromReflect` generic bound > - add a `map_apply()` helper method to implement `Map::apply()`, that inserts new values instead of ignoring them --- ## Changelog TODO Co-authored-by: james7132 <contact@jamessliu.com>
# Objective This is a rebase of bevyengine#3701 which is currently scheduled for 0.8 but is marked for adoption. > Fixes bevyengine#3609 ## Solution > - add an `insert_boxed()` method on the `Map` trait > - implement it for `HashMap` using a new `FromReflect` generic bound > - add a `map_apply()` helper method to implement `Map::apply()`, that inserts new values instead of ignoring them --- ## Changelog TODO Co-authored-by: james7132 <contact@jamessliu.com>
Objective
Fixes #3609
Solution
insert_boxed()
method on theMap
traitHashMap
using a newFromReflect
generic boundmap_apply()
helper method to implementMap::apply()
, that inserts new values instead of ignoring them