pub struct Attrs(pub Vec<(String, NodeValue)>);Expand description
A collection of node attributes stored as key-value pairs. Uses a Vec internally for better cache locality with small attribute counts (typically 3-6). Values can be either strings or JIDs, avoiding stringification overhead for JID attributes.
Tuple Fields§
§0: Vec<(String, NodeValue)>Implementations§
Source§impl Attrs
impl Attrs
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
Sourcepub fn get(&self, key: &str) -> Option<&NodeValue>
pub fn get(&self, key: &str) -> Option<&NodeValue>
Get a reference to the NodeValue for a key, or None if not found. Uses linear search which is efficient for small attribute counts.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Check if a key exists.
Sourcepub fn insert(&mut self, key: String, value: impl Into<NodeValue>)
pub fn insert(&mut self, key: String, value: impl Into<NodeValue>)
Insert a key-value pair. If the key already exists, update the value.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &NodeValue)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &NodeValue)>
Iterate over key-value pairs.
Sourcepub fn push(&mut self, key: String, value: impl Into<NodeValue>)
pub fn push(&mut self, key: String, value: impl Into<NodeValue>)
Push a key-value pair without checking for duplicates. Use this when building from a known-unique source (e.g., decoding).
Sourcepub fn push_value(&mut self, key: String, value: NodeValue)
pub fn push_value(&mut self, key: String, value: NodeValue)
Push a NodeValue directly without conversion. Slightly more efficient when you already have a NodeValue.
Trait Implementations§
Source§impl<'a> IntoIterator for &'a Attrs
Borrowed iterator implementation.
impl<'a> IntoIterator for &'a Attrs
Borrowed iterator implementation.
Source§impl IntoIterator for Attrs
Owned iterator implementation (consuming).
impl IntoIterator for Attrs
Owned iterator implementation (consuming).