pub struct NodeRef<'a, Ext: 'static = ()> { /* private fields */ }Expand description
Read-only handle to a node in the arena.
Implementations§
Source§impl<'a, Ext: 'static> NodeRef<'a, Ext>
impl<'a, Ext: 'static> NodeRef<'a, Ext>
pub fn id(&self) -> NodeId
Sourcepub fn dom(&self) -> &'a Dom<Ext>
pub fn dom(&self) -> &'a Dom<Ext>
Borrow the owning Dom<Ext>. Lifetime 'a matches the
underlying borrow that produced this NodeRef, so callers can
hold the returned reference for the same scope.
Exposed for extension traits (e.g. rdom-tui::TuiAccessors)
that need to reach back to dom-level helpers operating on
(dom, id) pairs (runtime focus, builtin form helpers, etc.).
Sourcepub fn node_type(&self) -> NodeType
pub fn node_type(&self) -> NodeType
§Panics
Panics if the id behind this NodeRef is not live (freed, or a
stale handle to a recycled slot). Dom::node does not validate
up front; check Dom::contains first when the id may be stale.
Sourcepub fn node_name(&self) -> &'a str
pub fn node_name(&self) -> &'a str
Canonical nodeName: element tag, or #text / #comment /
#document-fragment for non-elements.
§Panics
Panics if the id is not live; see NodeRef::node_type.
pub fn tag_name(&self) -> Option<&'a str>
Sourcepub fn ext(&self) -> Option<&'a Ext>
pub fn ext(&self) -> Option<&'a Ext>
Borrow the per-element extension data.
This is the hook by which rdom-tui (or any downstream crate
parameterizing Dom<Ext>) reads presentation / layout / styling
state attached to each Element. Returns None for Text / Comment /
Fragment nodes — those don’t carry Ext.
pub fn node_value(&self) -> Option<&'a str>
Sourcepub fn data(&self) -> Option<&'a str>
pub fn data(&self) -> Option<&'a str>
CharacterData.data — MDN alias for Text/Comment nodeValue. Same
behaviour, different name; exists because the spec treats these as
two different interface members.
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
textContent — concatenate the string content of this node and all
its descendants. Comments are excluded per spec.
pub fn parent_node(&self) -> Option<NodeRef<'a, Ext>>
Sourcepub fn parent_element(&self) -> Option<NodeRef<'a, Ext>>
pub fn parent_element(&self) -> Option<NodeRef<'a, Ext>>
Parent that is an element (skips fragment parents).
pub fn first_child(&self) -> Option<NodeRef<'a, Ext>>
pub fn last_child(&self) -> Option<NodeRef<'a, Ext>>
pub fn previous_sibling(&self) -> Option<NodeRef<'a, Ext>>
pub fn next_sibling(&self) -> Option<NodeRef<'a, Ext>>
pub fn has_child_nodes(&self) -> bool
pub fn child_nodes(&self) -> ChildIter<'a, Ext> ⓘ
pub fn first_element_child(&self) -> Option<NodeRef<'a, Ext>>
pub fn last_element_child(&self) -> Option<NodeRef<'a, Ext>>
pub fn previous_element_sibling(&self) -> Option<NodeRef<'a, Ext>>
pub fn next_element_sibling(&self) -> Option<NodeRef<'a, Ext>>
pub fn children(&self) -> ElementChildIter<'a, Ext> ⓘ
pub fn child_element_count(&self) -> usize
pub fn id_attr(&self) -> Option<&'a str>
pub fn get_attribute(&self, key: &str) -> Option<&'a str>
pub fn has_attribute(&self, key: &str) -> bool
pub fn has_class(&self, class: &str) -> bool
Sourcepub fn attributes(&self) -> impl Iterator<Item = (&'a str, &'a str)>
pub fn attributes(&self) -> impl Iterator<Item = (&'a str, &'a str)>
Iterate (name, value) pairs in deterministic order.
Sourcepub fn class_name(&self) -> &'a str
pub fn class_name(&self) -> &'a str
Raw class attribute value, or "" if absent. DOM
Element.className.
This is the unparsed string. For token-level access use
Self::class_list; for hot-path membership tests use
Self::has_class.
Sourcepub fn class_list(&self) -> DomTokenList
pub fn class_list(&self) -> DomTokenList
Snapshot of the element’s class tokens. DOM
Element.classList.
Hot-path footgun. Each call allocates a fresh Vec
snapshot. For per-paint or per-event membership checks,
prefer Self::has_class.
pub fn contains(&self, other: NodeId) -> bool
pub fn is_same_node(&self, other: NodeId) -> bool
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
true iff this node is reachable from the document root by
walking parent pointers. DOM Node.isConnected.
Sourcepub fn get_root_node(&self) -> NodeRef<'a, Ext>
pub fn get_root_node(&self) -> NodeRef<'a, Ext>
Walk parent pointers until none and return the topmost node.
DOM Node.getRootNode() (options ignored — no shadow DOM in
rdom).
Sourcepub fn matches(&self, selector: &str) -> bool
pub fn matches(&self, selector: &str) -> bool
Does this element match selector? DOM Element.matches.
Divergence from browser: browser throws SyntaxError on
malformed selectors; rdom returns false. Authors who need
to surface parser errors can call
Dom::matches directly.
Sourcepub fn closest(&self, selector: &str) -> Option<NodeRef<'a, Ext>>
pub fn closest(&self, selector: &str) -> Option<NodeRef<'a, Ext>>
Walk from this node (inclusive) up the ancestor chain and
return the first match. DOM Element.closest.
Same parser-error policy as Self::matches.
Sourcepub fn query_selector(&self, selector: &str) -> Option<NodeRef<'a, Ext>>
pub fn query_selector(&self, selector: &str) -> Option<NodeRef<'a, Ext>>
First descendant matching selector, in document order. DOM
Element.querySelector. The subject element itself is not
a candidate (spec).
Same parser-error policy as Self::matches.
Sourcepub fn query_selector_all(&self, selector: &str) -> NodeList<'a, Ext>
pub fn query_selector_all(&self, selector: &str) -> NodeList<'a, Ext>
All descendants matching selector, in document order, as a
snapshot NodeList. DOM Element.querySelectorAll. The
subject element itself is not a candidate.
Same parser-error policy as Self::matches; an unparseable
selector yields an empty list.
Sourcepub fn dataset(&self) -> DomStringMap<'a, Ext>
pub fn dataset(&self) -> DomStringMap<'a, Ext>
DOM HTMLElement.dataset — snapshot view of data-*
attributes keyed by their camelCase form.
Sourcepub fn tab_index(&self) -> Option<i32>
pub fn tab_index(&self) -> Option<i32>
DOM HTMLElement.tabIndex — raw tabindex attribute
parsed as i32. None when the attribute is absent or
unparseable.
Note: this is the raw value. The TUI-aware effective
tab index (honoring implicit focusability per
runtime::focus::tabindex) lives on
rdom_tui::TuiAccessors::effective_tab_index per §13 and
ships in M4b step 21.
DOM HTMLElement.hidden — true iff the hidden boolean
attribute is present.
Sourcepub fn content_editable(&self) -> &'static str
pub fn content_editable(&self) -> &'static str
DOM HTMLElement.contentEditable getter (HTML §6.8.1): the
canonical keyword of the attribute’s state — "true", "false"
or "plaintext-only", matched ASCII case-insensitively — and
"inherit" when the attribute is missing or invalid.
Sourcepub fn inner_html(&self) -> String
pub fn inner_html(&self) -> String
DOM Element.innerHTML getter — markup of this element’s
children. Delegates to Dom::inner_markup.
Hot-path footgun. Each call re-serializes the entire subtree; for tight loops, prefer attribute / child walks against the live tree.
Sourcepub fn outer_html(&self) -> String
pub fn outer_html(&self) -> String
DOM Element.outerHTML getter — markup of this element
including itself. Delegates to Dom::outer_markup.