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
I often find myself in a situation where I would like to insert a key
into a map via `#entry_ref` and then use the key from the resulting
entry.
```
// Get a byte slice from a buffer
let key = client.request.get(index);
// Insert the value (default)
let mut entry = match queues.entry_ref(&key) {
EntryRef::Occupied(entry) => entry,
EntryRef::Vacant(entry) => entry.insert_entry(Default::default()),
};
// Use the value
entry.get_mut().insert_back(client.id);
// Reuse the key instead of copying the bytes again
keys.insert(client.id, entry.key());
```
This is common enough that I'd love to have functions for it, similar to
`insert_entry`.
```
// Get a byte slice from a buffer
let key = client.request.get(index);
// Insert the value (default)
let mut entry = queues.entry_ref(&key).or_default_entry();
// Use the value
entry.get_mut().insert_back(client.id);
// Reuse the key instead of copying the bytes again
keys.insert(client.id, entry.key());
```
0 commit comments