pub struct PropMap(/* private fields */);Expand description
Ordered map of prop key-value pairs.
Uses a Vec for storage since widget props are typically small
(5-15 entries). Linear scan is faster than hashing for this size.
§Wire serialisation key order
Props are serialised to JSON via
into_json_map which collects into a
serde_json::Map. The workspace compiles serde_json without
the preserve_order feature, so Map is an alphabetical-key
BTreeMap equivalent. That keeps direct JSON serialisation stable
for protocol-facing code and prop regression tests in this crate.
Enabling preserve_order would make JSON serialisation
insertion-ordered and change the emitted wire shape.
Implementations§
Source§impl PropMap
impl PropMap
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Return a new value with the capacity set.
Sourcepub fn get_mut(&mut self, key: &str) -> Option<&mut PropValue>
pub fn get_mut(&mut self, key: &str) -> Option<&mut PropValue>
Get a mutable reference to a prop value by key.
Sourcepub fn insert(&mut self, key: impl Into<String>, value: impl Into<PropValue>)
pub fn insert(&mut self, key: impl Into<String>, value: impl Into<PropValue>)
Insert or replace a prop value.
Sourcepub fn remove(&mut self, key: &str) -> Option<PropValue>
pub fn remove(&mut self, key: &str) -> Option<PropValue>
Remove a prop by key, returning the old value if present.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Set or construct contains_key.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &PropValue)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &PropValue)>
Iterate over (key, value) pairs.
Sourcepub fn from_json_map(map: Map<String, Value>) -> Self
pub fn from_json_map(map: Map<String, Value>) -> Self
Convert from a serde_json Map.
Sourcepub fn into_json_map(self) -> Map<String, Value>
pub fn into_json_map(self) -> Map<String, Value>
Convert to a serde_json Map.
Trait Implementations§
Source§impl PartialEq for PropMap
impl PartialEq for PropMap
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Wire-canonical equality: null-valued entries are equivalent to
absent entries. The wire protocol encodes key removal by sending
null, so {} and {"a": null} are indistinguishable downstream
and must compare equal here. Without this, tree_diff +
apply_patch could not round-trip trees whose only difference
is a null-valued prop, because there is no protocol op that adds
an explicit null-valued key.