pub trait StyledNode {
// Required methods
fn type_name(&self) -> &str;
fn id(&self) -> Option<&str>;
fn classes(&self) -> Classes<'_>;
fn state(&self) -> State;
// Provided method
fn position(&self) -> Position { ... }
}Expand description
The minimal contract the cascade needs to match selectors against an element.
Implement this on your framework’s node type (e.g. a2ui’s ComponentModel,
or a plain app-state struct in a vanilla ratatui app).
For the draw-loop hot path prefer NodeRef (zero-allocation). OwnedNode
remains available for convenience where owned String/Vec<String> storage
is preferable.
Required Methods§
Sourcefn classes(&self) -> Classes<'_>
fn classes(&self) -> Classes<'_>
Class names — match CSS .class selectors.
Returns a Classes<'_> borrow view rather than an allocating
Vec<&str>. NodeRef makes this zero-allocation; OwnedNode
pays one Vec allocation (it is not the hot path). The cascade hoists
this call out of the per-rule loop so the cost is paid at most once per
node regardless.
Provided Methods§
Sourcefn position(&self) -> Position
fn position(&self) -> Position
Sibling position — for future :nth-child support.
This is optional: :nth-child matching is P3 and not yet wired into
the cascade, so compute does not consult it. The default returns an
empty Position. Override it only when you need :nth-child data at
some future point — until then, leaving the default avoids forcing every
node type to materialize sibling info.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".