pub struct AttributeEntry {
pub name: Cow<'static, str>,
/* private fields */
}Expand description
Represents a single attribute on a virtual DOM node.
Combines an attribute name with its corresponding value.
OPT 2: attribute names are Cow<'static, str>. The html! macro
emits Cow::Borrowed("class") for the common literal case so
attribute keys share a single static slice across the whole rendered
DOM, removing the per-attribute String heap allocation. The
AttributeValue::Text(String) payload keeps its owned allocation
(text values are user-supplied strings that almost always come
from string interpolation or runtime formatting).
Fields§
§name: Cow<'static, str>The name of the attribute.
get_name is public: ui/tests/view_factories collects attribute
names from outside this crate. get_mut / set stay crate-internal —
an attribute entry is built once by New and never rewritten.
Implementations§
Source§impl AttributeEntry
Implementation of the public read side of an attribute entry.
impl AttributeEntry
Implementation of the public read side of an attribute entry.
Sourcepub fn class_names(&self) -> Vec<String>
pub fn class_names(&self) -> Vec<String>
Returns the CSS class names this attribute carries.
The class attribute is the one place where a component’s
styling decisions become observable, so it needs a public read
side: a component library’s tests have to be able to assert
that a state actually landed on the right class, and an external
crate cannot read the raw attribute value.
Every shape the attribute can take is reported:
Css and CssRef contribute the class name they carry, Text
and StaticText contribute their string split on whitespace,
a Signal contributes the class list it currently holds — that
is the shape a reactive class: attribute takes — and the
remaining shapes, an event handler, contribute nothing, because
neither is a class list.
§Returns
Vec<String>- The class names, in the order they appear.
Sourcepub fn text_value(&self) -> Option<String>
pub fn text_value(&self) -> Option<String>
Returns the attribute’s value as text, when it carries one.
A Text or StaticText attribute is its own value; a Css or
CssRef attribute contributes its class name, because that is
the text the browser ends up showing for it. The remaining
shapes — a reactive signal, an event handler — carry no text.
§Returns
Option<String>- The value, when the attribute has one.