pub struct Attributes { /* private fields */ }Expand description
A runtime collection of HTML attributes with unique keys.
Attributes is map-like: each key appears at most once, and inserting the
same key again replaces the previous value. Do not rely on render order.
Prefer constructing Attributes with the attributes!
macro.
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.
Prefer the
attributes!
macro when writing attributes directly. This is mainly useful for
generated code or manual builders that already know how many attributes
they will insert.
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<&ViewPart>
pub fn get(&self, k: impl AsRef<str>) -> Option<&ViewPart>
Returns the view parts stored for attribute key k, if present.
Sourcepub fn insert(
&mut self,
cx: &Cx,
k: impl Into<String>,
v: impl AttributeValueViewParts,
) -> Option<ViewPart>
pub fn insert( &mut self, cx: &Cx, k: impl Into<String>, v: impl AttributeValueViewParts, ) -> Option<ViewPart>
Inserts or replaces an attribute.
The value is converted with AttributeValueViewParts.
If the key was already present, the previous rendered value is returned.
If the implementation of AttributeValueViewParts for v signals that
the attribute should not be present, ViewPart::empty will be used as
the value instead, which call cause the previous value to be removed
and the attribute will not be rendered in a view!.
Sourcepub fn remove(&mut self, k: impl AsRef<str>) -> Option<ViewPart>
pub fn remove(&mut self, k: impl AsRef<str>) -> Option<ViewPart>
Removes an attribute, returning its rendered value if the key was present.
Sourcepub fn extend(&mut self, iter: impl IntoIterator<Item = (String, ViewPart)>)
pub fn extend(&mut self, iter: impl IntoIterator<Item = (String, ViewPart)>)
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 rendered values.
Trait Implementations§
Source§impl AttributeViewParts for Attributes
impl AttributeViewParts for Attributes
Source§fn into_view_parts(self, cx: &Cx, parts: &mut PartsWriter<'_>)
fn into_view_parts(self, cx: &Cx, parts: &mut PartsWriter<'_>)
Source§impl Clone for Attributes
impl Clone for Attributes
Source§fn clone(&self) -> Attributes
fn clone(&self) -> Attributes
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more