@@ -48,7 +48,7 @@ Occupied case into an `&mut V`. Usage looks like:
48
48
```
49
49
50
50
```
51
- entry(key).get().unwrap_or_else(|entry| entry.insert(vec![])).push(val);
51
+ map. entry(key).get().unwrap_or_else(|entry| entry.insert(vec![])).push(val);
52
52
```
53
53
54
54
This is certainly * nicer* . No imports are needed, the Occupied case is handled, and we're closer
@@ -70,7 +70,6 @@ Replace `Entry::get` with the following two methods:
70
70
}
71
71
}
72
72
73
- #[unstable(feature = "collections",
74
73
/// Ensures a value is in the entry by inserting the result of the default function if empty,
75
74
/// and returns a mutable reference to the value in the entry.
76
75
pub fn default_with<F: FnOnce() -> V>(self. default: F) -> &'a mut V {
@@ -90,11 +89,11 @@ which allows the following:
90
89
91
90
```
92
91
// vec![] doesn't even allocate, and is only 3 ptrs big.
93
- entry(key).default(vec![]).push(val);
92
+ map. entry(key).default(vec![]).push(val);
94
93
```
95
94
96
95
```
97
- let val = entry(key).default_with(|| expensive(big, data));
96
+ let val = map. entry(key).default_with(|| expensive(big, data));
98
97
```
99
98
100
99
Look at all that ergonomics. * Look at it* . This pushes us more into the "one right way"
@@ -119,5 +118,11 @@ Settle for Result chumpsville or abandon this sugar altogether. Truly, fates wor
119
118
120
119
# Unresolved questions
121
120
122
- None.
121
+ ` default ` and ` default_with ` are universally reviled as * names* . Need a better name. Some candidates.
122
+
123
+ * set_default
124
+ * or_insert
125
+ * insert_default
126
+ * insert_if_vacant
127
+ * with_default
123
128
0 commit comments