-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 get_at_mut
to Map
trait
#8596
Comments
I assume this is for ordered maps? In which case, I think it makes sense to add these kinds of methods, but with a disclaimer that not all maps guarantee a particular order. |
Technically this is for any map actually; which makes me realize we need |
Oops I completely missed the fact that we already have |
Hello! I want to tackle this problem. I'm new here, so any help would be really appreciated @MrGVSV. Here's what I've been able to gather so far:
So my question is: |
Awesome! Yeah feel free to leave questions in #reflection-dev on Discord if you have any. Always great to have new contributors!
Good question! I don't think we should make the key mutable. I agree that that makes things a lot more complicated. On top of that, |
Mutable key on a hash map is plain wrong. |
# Objective Fixes #8596 ## Solution Change interface of the trait Map. Adjust implementations of this trait --- ## Changelog ### Changed - Interface of Map trait ### Added - `Map::get_at_mut` ## Migration Guide Every implementor of Map trait would need to implement `get_at_mut`. Which, judging by changes in this PR, should be fairly trivial.
What problem does this solve or what need does it fill?
Currently the solution to getting a mutable reference to the key/value at an index of a map is to get the key and value immutably, clone the key, then use that to index the map. This is unnecessarily inefficient and could easily be avoided.
What solution would you like?
A
get_at_mut
method that works likeget_at
, but returns mutable references.I might PR this myself later if I remember.
The text was updated successfully, but these errors were encountered: