You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-api[DEPRECATED; DO NOT USE]final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
Is there any way to recover the key used in the entry from an occupied entry? That is, I'm trying to write a multimap like with the following insert definition:
Got it. I just want to make sure the APIs play well together. Specifically, given that we want a way to to move keys out Entry, VacentEntry, and OccupiedEntry, I'd do the following:
Remove VacentEntry::into_key.
Rename remove_pair to remove or take as opposed to replacing it with an Into<(K, V)> implementation.
Add Into<K> implementations for converting entries back into their keys:
Note: I'm proposing (2) because having two different Into impls that do very different things (one mutates the map, the other doesn't is probably a bad idea.
Hm yeah that's actually a good point about Into<(K, V)> having odd behavior by mutating the map. I also agree that if we have key recover it'd be good to be consistent across entry types. Thanks for the good points @Stebalien!
The libs team discussed this recently and concluded:
It does seem odd to use Into for removal from the map, so we'd prefer to avoid.
Eventually adding Into seems good, but perhaps not necessary immediately
VacantEntry::into_key seems good enough for now, we can always add Into<K> later if necessary.
The remove method is unfortunately already taken
The take method is used on HashSet, setting precedent, but the semantics are removal for a mutable container, not consumption of the container (e.g. Option::take as well)
Another more plausible name for removal is remove_entry
As a result our conclusions were:
Let's add into_key, looking to add Into<K> later if necessary
B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-api[DEPRECATED; DO NOT USE]final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
Activity
alexcrichton commentedon Jun 15, 2016
Specifically covers:
VacantEntry::into_keyOccupiedEntry::remove_pairfor both
HashMapandBTreeMap.I would personally still hesitate a little on the name
remove_pair(specifically thepairpart) but otherwise seems good to me.alexcrichton commentedon Jul 13, 2016
🔔 This issue is now entering a cycle-long final comment period for stabilization 🔔
Note though that the libs team isn't entirely comfortable with the name
remove_pair, so we'd like to consider other possibilities during this FCP!seanmonstar commentedon Jul 13, 2016
I somewhat like
impl Into<(K, V)> for OccupiedEntry, so that it's thenlet mine = occupied.into();.alexcrichton commentedon Jul 13, 2016
Sounds like a great fit to me!
Stebalien commentedon Jul 23, 2016
Is there any way to recover the key used in the entry from an occupied entry? That is, I'm trying to write a multimap like with the following insert definition:
I don't want to remove the key/value pair from the hash-map, I just want my key back!
alexcrichton commentedon Jul 23, 2016
@Stebalien I believe not currently, no, but it is the subject of an RFC or two
Stebalien commentedon Jul 23, 2016
Got it. I just want to make sure the APIs play well together. Specifically, given that we want a way to to move keys out
Entry,VacentEntry, andOccupiedEntry, I'd do the following:VacentEntry::into_key.remove_pairtoremoveortakeas opposed to replacing it with anInto<(K, V)>implementation.Into<K>implementations for converting entries back into their keys:Note: I'm proposing (2) because having two different
Intoimpls that do very different things (one mutates the map, the other doesn't is probably a bad idea.alexcrichton commentedon Jul 25, 2016
Hm yeah that's actually a good point about
Into<(K, V)>having odd behavior by mutating the map. I also agree that if we have key recover it'd be good to be consistent across entry types. Thanks for the good points @Stebalien!Stebalien commentedon Jul 25, 2016
We can't actually write those
Intoimpls due to coherence... 😢.alexcrichton commentedon Aug 11, 2016
The libs team discussed this recently and concluded:
Intofor removal from the map, so we'd prefer to avoid.Intoseems good, but perhaps not necessary immediatelyVacantEntry::into_keyseems good enough for now, we can always addInto<K>later if necessary.removemethod is unfortunately already takentakemethod is used onHashSet, setting precedent, but the semantics are removal for a mutable container, not consumption of the container (e.g.Option::takeas well)remove_entryAs a result our conclusions were:
into_key, looking to addInto<K>later if necessaryremove_entryAuto merge of #35607 - alexcrichton:stabilize-1.12, r=brson
Auto merge of #35607 - alexcrichton:stabilize-1.12, r=brson
std: Stabilize APIs for the 1.12 release
std: Stabilize APIs for the 1.12 release