Skip to content

Commit 5442de0

Browse files
committed
update for libs team changes
1 parent a195994 commit 5442de0

File tree

1 file changed

+3
-66
lines changed

1 file changed

+3
-66
lines changed

text/0000-collection-recovery.md

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
# Summary
77

8-
Add element-recovery methods to the set types in `std`. Add key-recovery methods to the map types
9-
in `std` in order to facilitate this.
8+
Add element-recovery methods to the set types in `std`.
109

1110
# Motivation
1211

@@ -87,83 +86,21 @@ Add the following element-recovery methods to `std::collections::{BTreeSet, Hash
8786
```rust
8887
impl<T> Set<T> {
8988
// Like `contains`, but returns a reference to the element if the set contains it.
90-
fn element<Q: ?Sized>(&self, element: &Q) -> Option<&T>;
89+
fn get<Q: ?Sized>(&self, element: &Q) -> Option<&T>;
9190

9291
// Like `remove`, but returns the element if the set contained it.
93-
fn remove_element<Q: ?Sized>(&mut self, element: &Q) -> Option<T>;
92+
fn take<Q: ?Sized>(&mut self, element: &Q) -> Option<T>;
9493

9594
// Like `insert`, but replaces the element with the given one and returns the previous element
9695
// if the set contained it.
9796
fn replace(&mut self, element: T) -> Option<T>;
9897
}
9998
```
10099

101-
In order to implement the above methods, add the following key-recovery methods to
102-
`std::collections::{BTreeMap, HashMap}`:
103-
104-
```rust
105-
impl<K, V> Map<K, V> {
106-
// Like `get`, but additionally returns a reference to the entry's key.
107-
fn key_value<Q: ?Sized>(&self, key: &Q) -> Option<(&K, &V)>;
108-
109-
// Like `get_mut`, but additionally returns a reference to the entry's key.
110-
fn key_value_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<(&K, &mut V)>;
111-
112-
// Like `remove`, but additionally returns the entry's key.
113-
fn remove_key_value<Q: ?Sized>(&mut self, key: &Q) -> Option<(K, V)>;
114-
115-
// Like `insert`, but additionally replaces the key with the given one and returns the previous
116-
// key and value if the map contained it.
117-
fn replace(&mut self, key: K, value: V) -> Option<(K, V)>;
118-
}
119-
```
120-
121-
Add the following key-recovery methods to `std::collections::{btree_map, hash_map}::OccupiedEntry`:
122-
123-
```rust
124-
impl<'a, K, V> OccupiedEntry<'a, K, V> {
125-
// Like `get`, but additionally returns a reference to the entry's key.
126-
fn key_value(&self) -> (&K, &V);
127-
128-
// Like `get_mut`, but additionally returns a reference to the entry's key.
129-
fn key_value_mut(&mut self) -> (&K, &mut V);
130-
131-
// Like `into_mut`, but additionally returns a reference to the entry's key.
132-
fn into_key_value_mut(self) -> (&'a K, &'a mut V);
133-
134-
// Like `remove`, but additionally returns the entry's key.
135-
fn remove_key_value(self) -> (K, V);
136-
}
137-
```
138-
139-
Add the following key-recovery methods to `std::collections::{btree_map, hash_map}::VacantEntry`:
140-
141-
```rust
142-
impl<'a, K, V> VacantEntry<'a, K, V> {
143-
/// Returns a reference to the entry's key.
144-
fn key(&self) -> &K;
145-
146-
// Like `insert`, but additionally returns a reference to the entry's key.
147-
fn insert_key_value(self, value: V) -> (&'a K, &'a mut V);
148-
149-
// Returns the entry's key without inserting it into the map.
150-
fn into_key(self) -> K;
151-
}
152-
```
153-
154100
# Drawbacks
155101

156102
This complicates the collection APIs.
157103

158-
The distinction between `insert` and `replace` may be confusing. It would be more consistent to
159-
call `Set::replace` `Set::insert_element` and `Map::replace` `Map::insert_key_value`, but
160-
`BTreeMap` and `HashMap` do not replace equivalent keys in their `insert` methods, so rather than
161-
have `insert` and `insert_key_value` behave differently in that respect, `replace` is used instead.
162-
163104
# Alternatives
164105

165106
Do nothing.
166-
167-
# Unresolved questions
168-
169-
Are these the best method names?

0 commit comments

Comments
 (0)