Repository navigation
Closed
Labels
A-btreeArea: `std::collections::{BTreeMap, BTreeSet}`Area: `std::collections::{BTreeMap, BTreeSet}`A-hashtableArea: `std::collections::{HashMap, HashSet}`Area: `std::collections::{HashMap, HashSet}`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Description
Steps
- Implementation in
std(Add or_insert_with_key to Entry of HashMap/BTreeMap #70996) - Merge into
std - Implementation in
hashbrowncrate (Add or_insert_with_key to Entry of HashMap hashbrown#152) - Merge into
hashbrown - Stabilization (Stabilize or_insert_with_key #78083)
- Make pull request with documentation changes from
ChaiTRex/hashbrowntorust-lang/hashbrown(Imported new documentation for .or_insert_with_key hashbrown#217) - Close old issue requesting feature (Add hash_map::Entry.or_insert_with_key() method rfcs#1202)
Metadata
Metadata
Assignees
Labels
A-btreeArea: `std::collections::{BTreeMap, BTreeSet}`Area: `std::collections::{BTreeMap, BTreeSet}`A-hashtableArea: `std::collections::{HashMap, HashSet}`Area: `std::collections::{HashMap, HashSet}`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Activity
jonas-schievink commentedon Apr 11, 2020
That seems like the wrong PR
ChaiTRex commentedon Apr 11, 2020
@jonas-schievink Thank you. Corrected.
Also, added a 2015 issue that requested this feature so that it can be closed if this is accepted.
ChaiTRex commentedon Apr 12, 2020
Merged into
hashbrown(rust-lang/hashbrown#152) and intostdas unstable (#70996).a1phyr commentedon Oct 17, 2020
What does this feature need to be stabilized ?
ChaiTRex commentedon Oct 19, 2020
This is my first stabilization report, so please let me know if it's insufficient.
Stabilization report
Summary
This allows inserting key-derived values when a
HashMap/BTreeMapentry is vacant.The difference between this and
.or_insert_with(|| ... )is that this provides a reference to the key to the closure after it is moved with.entry(key_being_moved), avoiding the need to copy or clone the key.Examples
Edge cases
I cannot think of any edge cases.
Stabilization pull request
The stabilization pull request is #78083
Rollup merge of rust-lang#78083 - ChaiTRex:master, r=m-ou-se
Rollup merge of rust-lang#78083 - ChaiTRex:master, r=m-ou-se
jplatte commentedon Dec 21, 2020
Stabilized, this tracking issue can be closed AFAICT 🙂
ChaiTRex commentedon Feb 11, 2021
Note: Fully stabilized today in Rust 1.50 in
HashMapand inBTreeMap.Rollup merge of #78083 - ChaiTRex:master, r=m-ou-se