serde_json::Map has several methods for removing an entry:
.remove(key)
.swap_remove(key) (with preserve_order)
.shift_remove(key) (with preserve_order)
.remove_entry(key)
.swap_remove_entry(key) (with preserve_order)
.shift_remove_entry(key) (with preserve_order)
But poor serde_json::map::OccupiedEntry only has .remove().
This means we can't easily/efficiently get the owned key from an OccupiedEntry - we have to either borrow and clone it, or call .remove_entry(key) on the original map, which will re-hash the key. Neither of these are catastrophic, but it's extra work we can avoid, since the underlying OccupiedEntry for both BTreeMap and IndexMap have a remove_entry method.
Similarly, with preserve_order enabled, we can't easily remove the entry without messing up the order of later entries, since OccupiedEntry::remove() uses swap_remove rather than shift_remove.
Hence, this PR adds the five missing removal methods to serde_json::map::OccupiedEntry
serde_json::Map
has several methods for removing an entry:.remove(key)
.swap_remove(key)
(with preserve_order).shift_remove(key)
(with preserve_order).remove_entry(key)
.swap_remove_entry(key)
(with preserve_order).shift_remove_entry(key)
(with preserve_order)But poor
serde_json::map::OccupiedEntry
only has.remove()
.This means we can't easily/efficiently get the owned key from an
OccupiedEntry
- we have to either borrow and clone it, or call.remove_entry(key)
on the original map, which will re-hash the key. Neither of these are catastrophic, but it's extra work we can avoid, since the underlyingOccupiedEntry
for bothBTreeMap
andIndexMap
have aremove_entry
method.Similarly, with preserve_order enabled, we can't easily remove the entry without messing up the order of later entries, since
OccupiedEntry::remove()
usesswap_remove
rather thanshift_remove
.Hence, this PR adds the five missing removal methods to
serde_json::map::OccupiedEntry