pub struct MapView<'a, K, V>(/* private fields */);zeroize only.Expand description
A decoded map view that wipes owned entry storage on growth and drop. Lookup and duplicate-key handling match the ordinary map view.
Implementations§
Methods from Deref<Target = MapView<'a, K, V>>§
Sourcepub fn iter(&self) -> Iter<'_, (K, V)> ⓘ
pub fn iter(&self) -> Iter<'_, (K, V)> ⓘ
Iterate over all entries in wire order.
If duplicate keys exist, all occurrences are yielded.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Look up a value by key, returning the last occurrence (last-write-wins).
Accepts any type that K can borrow as, so map.get("key") works
when K is &str. O(n) scan.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if an entry with the given key exists.
Sourcepub fn iter_unique(&self) -> impl ExactSizeIterator<Item = &(K, V)>where
K: Ord,
pub fn iter_unique(&self) -> impl ExactSizeIterator<Item = &(K, V)>where
K: Ord,
Iterate over key-value pairs with duplicate keys removed.
Each distinct key is yielded exactly once, at the position of its
last wire occurrence, carrying that occurrence’s value — i.e.
last-write-wins, mirroring the merge semantics that an owned
HashMap decode applies. Callers that need first-occurrence position
should use iter and filter themselves.
Used by the generated view Serialize impl: a JSON object cannot
hold duplicate keys, but MapView preserves all wire entries
(including malformed duplicates), so the JSON encode path must
deduplicate.
The work happens when this is called, not lazily: it sorts an index
vector, O(n log n) over the wire-entry count regardless of how many
entries are duplicates, allocating one Vec<usize>. Survivors are
yielded in wire order. A map with at most one entry skips the sort.
§Panics
Only if K’s Ord is not a total order, in which case the
underlying sort_unstable_by may panic.
Sourcepub fn len_unique(&self) -> usizewhere
K: Ord,
pub fn len_unique(&self) -> usizewhere
K: Ord,
Count of distinct keys (iter_unique().len()). Same cost as
iter_unique; a caller that needs both should
call iter_unique once and take its len().
§Panics
As iter_unique.