pub struct OrderedMap { /* private fields */ }Expand description
remove shifts later entries down. Lookups are linear; that is the
intended trade for small maps and stable ordering.
PartialEq is hand-written, not derived (issue #909, ruled 2026-07-18 —
docs/decision-log.md “Map/record equality is insertion-order-insensitive”):
equality is content-based, comparing key→value pairs regardless of
insertion order — #{a:1,b:2} == #{b:2,a:1} is true. Only equality
ignores order; iter/keys/values
and every codec still walk entries in insertion order, unchanged. The
derived PartialEq this replaces compared entries as a Vec, which is
order-sensitive — the bug. Value::Map’s Arc::ptr_eq fast path (same
snapshot → instant true) lives one level up in impl PartialEq for Value; this impl is the structural fallback it calls into.
Implementations§
Source§impl OrderedMap
impl OrderedMap
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create an empty map with capacity for n entries.
Sourcepub fn contains_key(&self, key: &MapKey) -> bool
pub fn contains_key(&self, key: &MapKey) -> bool
Whether key is present.
Sourcepub fn get_mut(&mut self, key: &MapKey) -> Option<&mut Value>
pub fn get_mut(&mut self, key: &MapKey) -> Option<&mut Value>
Mutably borrow the value for key, or None if absent. The
intermediate-segment leg of the T1e projection RMW spine
(docs/t1e-spec.md §3): recursing a make_mut chain through a map
needs a mutable handle to an existing entry without touching
insertion order, which insert alone (add-or-replace)
can’t provide.
Sourcepub fn insert(&mut self, key: MapKey, value: Value) -> Option<Value>
pub fn insert(&mut self, key: MapKey, value: Value) -> Option<Value>
Insert value under key, returning the previous value if the key was
already present.
An existing key keeps its insertion position (only its value changes); a new key is appended, so first-insertion order is preserved.
Sourcepub fn remove(&mut self, key: &MapKey) -> Option<Value>
pub fn remove(&mut self, key: &MapKey) -> Option<Value>
Remove key, returning its value if it was present. Later entries shift
down, so insertion order among the survivors is preserved.
Trait Implementations§
Source§impl Clone for OrderedMap
impl Clone for OrderedMap
Source§fn clone(&self) -> OrderedMap
fn clone(&self) -> OrderedMap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OrderedMap
impl Debug for OrderedMap
Source§impl Default for OrderedMap
impl Default for OrderedMap
Source§fn default() -> OrderedMap
fn default() -> OrderedMap
Source§impl<'de> Deserialize<'de> for OrderedMap
impl<'de> Deserialize<'de> for OrderedMap
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Hand-written, not derived (issue #985, follow-up to #909): the derived
impl would deserialize entries verbatim as a Vec<(MapKey, Value)>,
letting a crafted or corrupt payload carry a duplicate key and
construct a map that violates the content-based Eq invariant above
— Eq assumes each key appears at most once. This decodes into the
same shape the derive would have produced, then walks the entries
through the same duplicate-key check the .inkb/.inkt/transcript
decoders use (rejecting rather than silently keeping the last
occurrence — a legitimate encoder never emits a repeat, since
insert de-duplicates on the write side, so a repeat is corrupt
input, never a panic).
Source§impl FromIterator<(MapKey, Value)> for OrderedMap
impl FromIterator<(MapKey, Value)> for OrderedMap
Source§impl PartialEq for OrderedMap
impl PartialEq for OrderedMap
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Content comparison: same number of entries, and every key in self
maps to an equal value in other. Order-insensitive by construction
(a lookup by key, not a positional walk) — the len check is a fast
path (mismatched sizes can never be equal, and it makes the
same-length-different-keys case cheap to reject), and the per-entry
get gives each comparison the same Value::eq Arc::ptr_eq
shortcuts as any other structural compare. O(n) entries, each a
linear get — O(n^2) worst case, the accepted trade for small,
game-scale maps (same trade get/insert/remove already make).