Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow a `HashMap` and `BTreeMap` entry to be replaced. #44286
Comments
Binero
changed the title
Allow to replace a `HashMap` and `BTreeMap` entry to be replaced.
Allow a `HashMap` and `BTreeMap` entry to be replaced.
Sep 3, 2017
Mark-Simulacrum
added
C-feature-request
T-libs
labels
Sep 5, 2017
This comment has been minimized.
This comment has been minimized.
|
While it is indeed a missing API, there are several issues with this new API implemented in PR #44278:
I think
And probably that's it. If we need to replace key for some reason, |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Oh, it is not public API, thanks.
But this function does not allow to replace key without replacing value. BTW, there's already a function to replace value, it's called insert. So if we had
Please ignore that. |
This comment has been minimized.
This comment has been minimized.
|
I will take a look at |
This comment has been minimized.
This comment has been minimized.
|
@stepancheg I think it's probably better to have |
Binero
added a commit
to Binero/rust
that referenced
this issue
Oct 9, 2017
Binero
referenced this issue
Oct 30, 2017
Merged
Addressed issues raised in #44286. (`OccupiedEntry::replace_entry`) #45152
Binero
added a commit
to Binero/rust
that referenced
this issue
Nov 11, 2017
bors
added a commit
that referenced
this issue
Nov 11, 2017
bors
added a commit
that referenced
this issue
Nov 11, 2017
dtolnay
added
C-tracking-issue
and removed
C-feature-request
labels
Nov 18, 2017
SimonSapin
added
the
B-unstable
label
Mar 17, 2018
This comment has been minimized.
This comment has been minimized.
|
This has been in Nightly for long enough that I’m inclined to stabilize, but I don’t quite understand the use case. @Binero, can you explain some more why it can be important to recover the old key rather than the new one (passed to |
This comment has been minimized.
This comment has been minimized.
|
It is quite a niche function, so it's certainly not instantly obvious where this would be useful. That said, it has some uses when you want to for example lower the memory footprint of a If either |
Binero commentedSep 3, 2017
•
edited by dtolnay
At the moment the only way to replace a map entry with a new one, swallows the old key. In cases the user wants to keep the old key, the only way to do so is to first
remove_entryand to theninserta new one. This requires two map look-ups.As the Entry API aims to make operations that would otherwise require two look-ups into operations that require only one, the replacing of an entry is an obvious hole in the API.