Module selector
Available on crate features
html and http only.Expand description
Native CSS selector parsing and matching.
This module provides a small, dependency-free CSS selector engine for
the subset of selectors that can be evaluated while streaming HTML
(no sibling lookahead, no full-document state). It is the foundation
for rama’s streaming HTML parser/rewriter, but is also usable on its
own to match selectors against any tree that implements
SelectorSubject — including the in-memory Dom provided here.
§Supported selectors
| Pattern | Meaning |
|---|---|
* | any element |
E | an element of type E (ASCII case-insensitive) |
E.cls | an E with class cls |
E#id | an E with id id |
E[a] | an E with an a attribute |
E[a=v] | value exactly v |
E[a~=v] | whitespace-separated list containing v |
E[a^=v] E[a$=v] E[a*=v] | prefix / suffix / substring |
E[a|=v] | v or v- prefix |
E[a=v i] / E[a=v s] | case-insensitive / case-sensitive value |
E:nth-child(An+B) E:first-child | structural position |
E:nth-of-type(An+B) E:first-of-type | structural position by type |
E:not(s) | negation of a combinator-free compound s |
E F / E > F | descendant / child combinator |
a, b, c | selector list (matches if any matches) |
Sibling combinators (+, ~), :has(), :is(), :where(),
namespaces, pseudo-elements, and the non-streamable structural pseudos
(:last-child, :only-child, :last-of-type, :only-of-type,
:nth-last-*) are intentionally rejected with a SelectorError.
Structs§
- Compound
- A compound selector: an optional type/universal selector plus zero or more subclass selectors, all of which must match the same element.
- Dom
- A simple arena-backed element tree.
- Element
- A cheap, copyable view of an element in a
Dom. - NodeId
- Handle to an element within a
Dom. - Selector
- A parsed CSS selector string.
Enums§
- Selector
Error - Error returned when parsing a CSS selector string fails, or when it uses a construct outside the streaming-safe supported subset.
Traits§
- Selector
Subject - A read-only view of an element, providing exactly what the selector
matcher needs. Implement it for your own tree to match selectors
against it, or use the in-memory
Dom.