# Impl IndexMut for HashMap

**URL:** https://internals.rust-lang.org/t/impl-indexmut-for-hashmap/10963
**Category:** libs
**Created:** [September 18, 2019, 3:18pm UTC](https://internals.rust-lang.org/t/impl-indexmut-for-hashmap/10963 "2019-09-18T15:18:10Z")
**Posts on this page:** 3
**Page:** 2

<div class="post-metadata">

### Author: ![RustyYato](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/rustyyato/32/13627_2.png) [@RustyYato](https://internals.rust-lang.org/u/RustyYato)
#### Post date: [September 22, 2019, 7:53am UTC](https://internals.rust-lang.org/t/impl-indexmut-for-hashmap/10963/21 "2019-09-22T07:53:12Z")

</div>

That is implementation defined. If you see my propsal above, we could always use `index_assign` when you have `foo[index] = value`, but give it the default impl to defer to `index_mut` to prevent a breaking change.

We can then change `HashMap` to update only on `index_assign` so that just accessing an element via `index_mut` doesn't change anything.

---

<div class="post-metadata">

### Author: ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)
#### Post date: [September 22, 2019, 11:39am UTC](https://internals.rust-lang.org/t/impl-indexmut-for-hashmap/10963/22 "2019-09-22T11:39:42Z")

</div>

To me there isn't a dramatic difference between `foo[i] = v` and `foo.insert(i, v)`, so I don't really miss it. I don't even use `v = foo[i]`, because most of the time I don't know if they key is present, so I have to use `.get()` or `.entry()` anyway.

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)
#### Post date: [December 21, 2019, 11:39am UTC](https://internals.rust-lang.org/t/impl-indexmut-for-hashmap/10963/23 "2019-12-21T11:39:45Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/impl-indexmut-for-hashmap/10963.md?page=1)
