-
Notifications
You must be signed in to change notification settings - Fork 12.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
Remove IndexMut
impl from various collections to prepare for possible IndexSet
in the future
#23448
Comments
triage: P-backcompat-libs I-needs-decision (1.0 beta) |
triage: P-backcompat-libs (1.0 beta) |
I was just starting to prep a PR to resolve this by removing the impl, as you suggested. :) |
Don't we want to keep the implementation on |
@alexcrichton Depending on the exact way that For now, removing these impls will give us the most freedom when we do incorporate |
It seems weird to have this and insert -- insert has a return value, though. This would be a super-annoying ergonomic regression in the interim. What's the expected timeline for something like IndexSet? 1.1? |
Oh actually upon reflection most usages I know are Index, not IndexMut. Not as awful a regression. |
It should be possible to move in, out, and take references with the |
This commit removes the `IndexMut` impls on `HashMap` and `BTreeMap`, in order to future-proof the API against the eventual inclusion of an `IndexSet` trait. Ideally, we would eventually be able to support: ```rust map[owned_key] = val; map[borrowed_key].mutating_method(arguments); &mut map[borrowed_key]; ``` but to keep the design space as unconstrained as possible, we do not currently want to support `IndexMut`, in case some other strategy will eventually be needed. Code currently using mutating index notation can use `get_mut` instead. [breaking-change] Closes rust-lang#23448
…nkro This commit removes the `IndexMut` impls on `HashMap` and `BTreeMap`, in order to future-proof the API against the eventual inclusion of an `IndexSet` trait. Ideally, we would eventually be able to support: ```rust map[owned_key] = val; map[borrowed_key].mutating_method(arguments); &mut map[borrowed_key]; ``` but to keep the design space as unconstrained as possible, we do not currently want to support `IndexMut`, in case some other strategy will eventually be needed. Code currently using mutating index notation can use `get_mut` instead. [breaking-change] Closes rust-lang#23448 r? @gankro
…nkro This commit removes the `IndexMut` impls on `HashMap` and `BTreeMap`, in order to future-proof the API against the eventual inclusion of an `IndexSet` trait. Ideally, we would eventually be able to support: ```rust map[owned_key] = val; map[borrowed_key].mutating_method(arguments); &mut map[borrowed_key]; ``` but to keep the design space as unconstrained as possible, we do not currently want to support `IndexMut`, in case some other strategy will eventually be needed. Code currently using mutating index notation can use `get_mut` instead. [breaking-change] Closes rust-lang#23448 r? @gankro
|
It feels odd that Imho we should keep |
I believe we intend to eventually extend the index traits with the ability to override the
x[y] = z
syntax specifically using a trait likeIndexSet
. This would allow hashmaps to be used likemap[key] = value
and have that insert the key, unlike today wheremap[key] = value
will panic ifkey
is not already present.To pave the way, the simplest thing is to remove the
IndexMut
operator from those collections where we would anticipate growing on demand.I believe that would be
btree
,hash_map
, and possiblevec_deque
andvec_map
.Thoughts?
cc @aturon @alexcrichton @gankro
The text was updated successfully, but these errors were encountered: