Skip to content
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

Tracking for map_entry_recover_keys #34285

Closed
seanmonstar opened this Issue Jun 15, 2016 · 10 comments

Comments

Projects
None yet
4 participants
@seanmonstar
Copy link
Contributor

seanmonstar commented Jun 15, 2016

No description provided.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jun 15, 2016

Specifically covers:

  • VacantEntry::into_key
  • OccupiedEntry::remove_pair

for both HashMap and BTreeMap.

I would personally still hesitate a little on the name remove_pair (specifically the pair part) but otherwise seems good to me.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented 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

This comment has been minimized.

Copy link
Contributor Author

seanmonstar commented Jul 13, 2016

I somewhat like impl Into<(K, V)> for OccupiedEntry, so that it's then let mine = occupied.into();.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 13, 2016

Sounds like a great fit to me!

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented 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:

        let mut key = (key, 0);
        loop {
            match self.values.entry(key) {
                Entry::Vacant(e) => {
                    let idx = e.key().1;
                    e.insert(value);
                    return idx;
                },
                Entry::Occupied(e) => {
                    key = e.??? /* What here? */
                    key.1 += 1;
                }
            }
        }

I don't want to remove the key/value pair from the hash-map, I just want my key back!

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 23, 2016

@Stebalien I believe not currently, no, but it is the subject of an RFC or two

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented 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, and OccupiedEntry, I'd do the following:

  1. Remove VacentEntry::into_key.
  2. Rename remove_pair to remove or take as opposed to replacing it with an Into<(K, V)> implementation.
  3. Add Into<K> implementations for converting entries back into their keys:
impl Into<K> for Entry {}
impl Into<K> for OccupiedEntry {}
impl Into<K> for VacantEntry {}

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.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented 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

This comment has been minimized.

Copy link
Contributor

Stebalien commented Jul 25, 2016

We can't actually write those Into impls due to coherence... 😢.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Aug 11, 2016

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
  • Let's name the removal method remove_entry

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 11, 2016

std: Stabilize APIs for the 1.12 release
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 18, 2016

std: Stabilize APIs for the 1.12 release
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529

bors added a commit that referenced this issue Aug 18, 2016

Auto merge of #35607 - alexcrichton:stabilize-1.12, r=brson
std: Stabilize APIs for the 1.12 release

Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes #27708
cc #27709
Closes #32313
Closes #32630
Closes #32713
Closes #34029
Closes #34392
Closes #34285
Closes #34529

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 19, 2016

std: Stabilize APIs for the 1.12 release
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 19, 2016

std: Stabilize APIs for the 1.12 release
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529

bors added a commit that referenced this issue Aug 20, 2016

Auto merge of #35607 - alexcrichton:stabilize-1.12, r=brson
std: Stabilize APIs for the 1.12 release

Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes #27708
cc #27709
Closes #32313
Closes #32630
Closes #32713
Closes #34029
Closes #34392
Closes #34285
Closes #34529

@bors bors closed this in #35607 Aug 20, 2016

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 23, 2016

std: Stabilize APIs for the 1.12 release
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529

pmatos pushed a commit to LinkiTools/rust that referenced this issue Sep 27, 2016

std: Stabilize APIs for the 1.12 release
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.