pub struct Attrs(pub Vec<(Cow<'static, str>, 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.
Keys use Cow<'static, str> to avoid heap allocation for compile-time-known strings
(e.g., “type”, “id”, “to”) which are the vast majority of attribute keys.
Tuple Fields§
§0: Vec<(Cow<'static, str>, 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: impl Into<Cow<'static, str>>,
value: impl Into<NodeValue>,
)
pub fn insert( &mut self, key: impl Into<Cow<'static, str>>, 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 = (&Cow<'static, str>, &NodeValue)>
pub fn iter(&self) -> impl Iterator<Item = (&Cow<'static, str>, &NodeValue)>
Iterate over key-value pairs.
Sourcepub fn push(
&mut self,
key: impl Into<Cow<'static, str>>,
value: impl Into<NodeValue>,
)
pub fn push( &mut self, key: impl Into<Cow<'static, str>>, 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).
Trait Implementations§
Source§impl<'a> IntoIterator for &'a Attrs
Borrowed iterator implementation.
impl<'a> IntoIterator for &'a Attrs
Borrowed iterator implementation.
Source§type Item = (&'a Cow<'static, str>, &'a NodeValue)
type Item = (&'a Cow<'static, str>, &'a NodeValue)
Source§impl IntoIterator for Attrs
Owned iterator implementation (consuming).
impl IntoIterator for Attrs
Owned iterator implementation (consuming).