Skip to main content

NodeRef

Struct NodeRef 

Source
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>

Source

pub fn id(&self) -> NodeId

Source

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.).

Source

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.

Source

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.

Source

pub fn tag_name(&self) -> Option<&'a str>

Source

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.

Source

pub fn node_value(&self) -> Option<&'a str>

Source

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.

Source

pub fn text_content(&self) -> String

textContent — concatenate the string content of this node and all its descendants. Comments are excluded per spec.

Source

pub fn parent_node(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn parent_element(&self) -> Option<NodeRef<'a, Ext>>

Parent that is an element (skips fragment parents).

Source

pub fn first_child(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn last_child(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn previous_sibling(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn next_sibling(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn has_child_nodes(&self) -> bool

Source

pub fn child_nodes(&self) -> ChildIter<'a, Ext> ⓘ

Source

pub fn first_element_child(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn last_element_child(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn previous_element_sibling(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn next_element_sibling(&self) -> Option<NodeRef<'a, Ext>>

Source

pub fn children(&self) -> ElementChildIter<'a, Ext> ⓘ

Source

pub fn child_element_count(&self) -> usize

Source

pub fn id_attr(&self) -> Option<&'a str>

Source

pub fn get_attribute(&self, key: &str) -> Option<&'a str>

Source

pub fn has_attribute(&self, key: &str) -> bool

Source

pub fn has_class(&self, class: &str) -> bool

Source

pub fn attributes(&self) -> impl Iterator<Item = (&'a str, &'a str)>

Iterate (name, value) pairs in deterministic order.

Source

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.

Source

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.

Source

pub fn contains(&self, other: NodeId) -> bool

Source

pub fn is_same_node(&self, other: NodeId) -> bool

Source

pub fn is_connected(&self) -> bool

true iff this node is reachable from the document root by walking parent pointers. DOM Node.isConnected.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn dataset(&self) -> DomStringMap<'a, Ext>

DOM HTMLElement.dataset — snapshot view of data-* attributes keyed by their camelCase form.

Source

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.

Source

pub fn hidden(&self) -> bool

DOM HTMLElement.hidden — true iff the hidden boolean attribute is present.

Source

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.

Source

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.

Source

pub fn outer_html(&self) -> String

DOM Element.outerHTML getter — markup of this element including itself. Delegates to Dom::outer_markup.

Trait Implementations§

Source§

impl<'a, Ext: Clone + 'static> Clone for NodeRef<'a, Ext>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, Ext: Copy + 'static> Copy for NodeRef<'a, Ext>

Auto Trait Implementations§

§

impl<'a, Ext = ()> !RefUnwindSafe for NodeRef<'a, Ext>

§

impl<'a, Ext = ()> !Send for NodeRef<'a, Ext>

§

impl<'a, Ext = ()> !Sync for NodeRef<'a, Ext>

§

impl<'a, Ext = ()> !UnwindSafe for NodeRef<'a, Ext>

§

impl<'a, Ext> Freeze for NodeRef<'a, Ext>
where &'a Dom<Ext>: Freeze,

§

impl<'a, Ext> Unpin for NodeRef<'a, Ext>
where &'a Dom<Ext>: Unpin,

§

impl<'a, Ext> UnsafeUnpin for NodeRef<'a, Ext>
where &'a Dom<Ext>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.