pub struct Attributes { /* private fields */ }Expand description
A runtime collection of HTML attributes with unique keys.
Each key appears at most once. Inserting the same key again replaces its
value. Attribute order is unspecified.
Prefer constructing Attributes with the attributes!
macro.
Keys and values are captured when inserted. The collection can be built separately from the element that renders it.
Implementations§
Source§impl Attributes
impl Attributes
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty attribute collection.
Prefer the
attributes!
macro when writing attributes directly. Use this constructor when the
collection must be populated incrementally.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty attribute collection with space for at least capacity
attributes.
Sourcepub fn contains_key(&self, k: impl AsRef<str>) -> bool
pub fn contains_key(&self, k: impl AsRef<str>) -> bool
Returns true if this collection contains an attribute with key k.
Sourcepub fn get(&self, k: impl AsRef<str>) -> Option<&AttributeValue>
pub fn get(&self, k: impl AsRef<str>) -> Option<&AttributeValue>
Returns the captured value stored for attribute key k, if present.
Sourcepub fn insert(
&mut self,
cx: &Cx,
k: impl AttributeKeyViewParts,
v: impl AttributeValueViewParts,
) -> Option<AttributeValue>
pub fn insert( &mut self, cx: &Cx, k: impl AttributeKeyViewParts, v: impl AttributeValueViewParts, ) -> Option<AttributeValue>
Inserts or replaces an attribute.
Returns the previous value if the key was present. If v reports
that its attribute should be omitted, stores
AttributeValue::Absent. This still replaces the previous value
and retains the key, but renders no attribute.
Sourcepub fn remove(&mut self, k: impl AsRef<str>) -> Option<AttributeValue>
pub fn remove(&mut self, k: impl AsRef<str>) -> Option<AttributeValue>
Removes an attribute, returning its captured value if the key was present.
Sourcepub fn extend(
&mut self,
iter: impl IntoIterator<Item = (AttributeKey, AttributeValue)>,
)
pub fn extend( &mut self, iter: impl IntoIterator<Item = (AttributeKey, AttributeValue)>, )
Inserts every (key, value) entry from iter, replacing any keys
already present.
Sourcepub fn iter(&self) -> <&Self as IntoIterator>::IntoIter
pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter
Returns an iterator over attribute keys and captured values.