pub enum VirtualNode<T = ()> {
Element {
tag: Tag,
attributes: Vec<AttributeEntry>,
children: Vec<VirtualNode>,
key: Option<String>,
props: Option<Box<T>>,
},
Text(TextNode),
Fragment(Vec<VirtualNode>),
Dynamic(DynamicNode),
Empty,
}Expand description
Represents a node in the virtual DOM tree.
The core enum representing elements, text, fragments, and empty nodes.
The generic parameter T carries the component props type for component nodes.
For non-component nodes, T defaults to ().
Variants§
Element
An element node with a tag, attributes, children, and optional props.
Fields
attributes: Vec<AttributeEntry>The attributes attached to this element.
children: Vec<VirtualNode>The child nodes.
Text(TextNode)
A text node containing string content and an optional reactive signal.
Fragment(Vec<VirtualNode>)
A fragment of multiple nodes without a wrapper element.
Dynamic(DynamicNode)
A dynamic node that re-renders based on signal changes.
Empty
An empty placeholder node.
Implementations§
Source§impl<T> VirtualNode<T>
Implementation of virtual node construction and property extraction.
impl<T> VirtualNode<T>
Implementation of virtual node construction and property extraction.
Sourcepub fn try_get_tag_name(&self) -> Option<String>
pub fn try_get_tag_name(&self) -> Option<String>
Returns the tag name if this is an element or component node.
§Returns
Option<String>- The tag name, orNoneif not an element.
Sourcepub fn get_children(&self) -> &[VirtualNode]
pub fn get_children(&self) -> &[VirtualNode]
Returns the children of this node as a borrowed slice.
Returns an empty slice for Empty, the children of Element
and Fragment variants, and an empty slice for Text /
Dynamic. Zero-copy; callers can iterate without cloning.
§Returns
&[VirtualNode]- The children, or an empty slice.
Sourcepub fn get_first_child(&self) -> Option<&VirtualNode>
pub fn get_first_child(&self) -> Option<&VirtualNode>
Returns the first child of this node as a borrowed reference, if any.
Returns None when there are no children; otherwise returns
a reference to the first child. Zero-copy; replaces the
previous get_child_node helper that cloned the entire
children subtree per render.
§Returns
Option<&VirtualNode>- The first child, orNone.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Sourcepub fn try_get_props(&self) -> Option<T>where
T: Clone,
pub fn try_get_props(&self) -> Option<T>where
T: Clone,
Clones the props of this node.
§Returns
Option<T>- The cloned props, orNoneif this node has no props.
Sourcepub fn try_get_children(&self) -> Option<&[VirtualNode]>
pub fn try_get_children(&self) -> Option<&[VirtualNode]>
Returns the children of this node as a borrowed slice.
Equivalent to Self::get_children but exposes the raw
Option<&[VirtualNode]> shape for callers that want to
distinguish “no children” from “empty children” (Element
without children vs. Text/Dynamic/Empty).
§Returns
Option<&[VirtualNode]>- The children, orNone.
Sourcepub fn extend_attributes<I>(self, extra: I) -> Selfwhere
I: IntoIterator<Item = AttributeEntry>,
pub fn extend_attributes<I>(self, extra: I) -> Selfwhere
I: IntoIterator<Item = AttributeEntry>,
Extends this node’s attribute list with the given entries, then
returns the node. If the node is not an Element variant, the
entries are dropped and the node is returned unchanged.
Used by the html! macro to splice class / style / event
handler attributes onto a component-returned node without forcing
a let mut binding in the generated code.
§Arguments
I: IntoIterator<Item = AttributeEntry>- The extra entries to append.
§Returns
Self- The node with extended attributes (or unchanged).
Sourcepub fn key(&self) -> Option<&str>
pub fn key(&self) -> Option<&str>
Returns the diffing key of this node, if it has one.
Recognizes keys on Element variants. Other variants
(Text, Fragment, Dynamic, Empty) do not have keys.
This matches the renderer’s get_node_key semantics
in core/src/renderer/render/impl.rs.
§Returns
Option<&str>- The key, orNoneif this node has no key or is not anElementvariant.
Source§impl VirtualNode<()>
Implementation of virtual node construction for VirtualNode<()>.
impl VirtualNode<()>
Implementation of virtual node construction for VirtualNode<()>.
Sourcepub fn create_dynamic<F>(render_fn: F) -> Selfwhere
F: FnMut(&mut HookContext) -> Self + 'static,
pub fn create_dynamic<F>(render_fn: F) -> Selfwhere
F: FnMut(&mut HookContext) -> Self + 'static,
Trait Implementations§
Source§impl<T: Clone> Clone for VirtualNode<T>
Clones a VirtualNode<T> by deep-copying all fields.
impl<T: Clone> Clone for VirtualNode<T>
Clones a VirtualNode<T> by deep-copying all fields.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clones the VirtualNode by reusing shared, cheap-to-clone state where possible.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for VirtualNode<T>
Debug formatting for VirtualNode<T>.
impl<T: Debug> Debug for VirtualNode<T>
Debug formatting for VirtualNode<T>.
Skips Dynamic inner details and props for brevity.
Source§impl<T> Default for VirtualNode<T>
Default implementation returns VirtualNode::Empty.
impl<T> Default for VirtualNode<T>
Default implementation returns VirtualNode::Empty.
Source§fn default() -> Self
fn default() -> Self
Constructs a default VirtualNode value.
Source§impl From<&[VirtualNode]> for VirtualNode
Converts a borrowed [VirtualNode] slice into a VirtualNode.
impl From<&[VirtualNode]> for VirtualNode
Converts a borrowed [VirtualNode] slice into a VirtualNode.
OPT 21: this lets call sites that hold node.get_children() (a
&[VirtualNode]) hand the children straight to the html! macro’s
(expr).into() dispatch without first cloning into a Vec. The
slice is materialised exactly once at the conversion site — same
number of clones as the old get_child_node helper performed
(zero for empty, one for single child, N for fragment) but moved
out of the helper so any caller that just wants to peek at the
children pays nothing.
Source§fn from(children: &[VirtualNode]) -> Self
fn from(children: &[VirtualNode]) -> Self
Source§impl From<&str> for VirtualNode
Converts a &str into a text virtual node.
impl From<&str> for VirtualNode
Converts a &str into a text virtual node.
Source§fn from(text: &str) -> Self
fn from(text: &str) -> Self
Converts this string slice into a text virtual node.
The &str may not be 'static, so we route through Cow::Owned
(small heap allocation) — runtime-evaluated text typically comes
here via format!, interpolated messages, or formatted signal
values. Macro-generated literal text takes the Cow::Borrowed
fast path in [crate::html::HtmlNode::Text] instead.
§Returns
VirtualNode- A text virtual node.
§Arguments
&str- Input value to convert from.
Source§impl<F> From<F> for VirtualNode
Wraps a FnMut(&mut HookContext) -> VirtualNode closure into a DynamicNode.
impl<F> From<F> for VirtualNode
Wraps a FnMut(&mut HookContext) -> VirtualNode closure into a DynamicNode.
This enables writing {move |_: &mut HookContext| html! { ... }} directly in HTML markup
without explicit DynamicNode construction.
Source§impl From<Option<Vec<VirtualNode>>> for VirtualNode
Converts an Option<Vec<VirtualNode>> into a VirtualNode.
impl From<Option<Vec<VirtualNode>>> for VirtualNode
Converts an Option<Vec<VirtualNode>> into a VirtualNode.
Some(vec) converts the vector into a VirtualNode::Fragment (or Empty
if the vector is empty), None returns VirtualNode::Empty.
§Returns
VirtualNode- AVirtualNode::FragmentifSomewith nodes,VirtualNode::EmptyifNoneor the vector is empty.
Source§fn from(nodes: Option<Vec<VirtualNode>>) -> Self
fn from(nodes: Option<Vec<VirtualNode>>) -> Self
Lifts an Option<Vec<VirtualNode>> into a VirtualNode (unwraps or falls back to empty).
§Arguments
Option<Vec<VirtualNode>>- Input value to convert from.
Source§impl From<Option<VirtualNode>> for VirtualNode
Converts an Option<VirtualNode> into a VirtualNode.
impl From<Option<VirtualNode>> for VirtualNode
Converts an Option<VirtualNode> into a VirtualNode.
Some(node) returns the inner node, None returns VirtualNode::Empty.
§Returns
VirtualNode- The inner node ifSome, otherwiseVirtualNode::Empty.
Source§fn from(node: Option<VirtualNode>) -> Self
fn from(node: Option<VirtualNode>) -> Self
Lifts an Option<VirtualNode> into a VirtualNode (unwraps or falls back to empty).
§Arguments
Option<VirtualNode>- Input value to convert from.
Source§impl<T> From<Signal<T>> for VirtualNode
Converts a signal into a reactive text virtual node.
impl<T> From<Signal<T>> for VirtualNode
Converts a signal into a reactive text virtual node.
Source§impl From<String> for VirtualNode
Converts a String into a text virtual node.
impl From<String> for VirtualNode
Converts a String into a text virtual node.
Source§impl From<Vec<VirtualNode>> for VirtualNode
Converts a Vec<VirtualNode> into a VirtualNode::Fragment.
impl From<Vec<VirtualNode>> for VirtualNode
Converts a Vec<VirtualNode> into a VirtualNode::Fragment.
This enables using a Vec<VirtualNode> directly in the html! macro
without manually wrapping it in VirtualNode::Fragment(...).
§Returns
VirtualNode- AVirtualNode::Fragmentcontaining the nodes, orVirtualNode::Emptyif the vector is empty.
Source§fn from(nodes: Vec<VirtualNode>) -> Self
fn from(nodes: Vec<VirtualNode>) -> Self
Lifts a Vec<VirtualNode> into a single VirtualNode via wrapping or unwrapping.
§Arguments
Vec<VirtualNode>- Input value to convert from.
Source§impl From<bool> for VirtualNode
Converts a bool into a text virtual node.
impl From<bool> for VirtualNode
Converts a bool into a text virtual node.
Source§impl From<i32> for VirtualNode
Converts an i32 into a text virtual node.
impl From<i32> for VirtualNode
Converts an i32 into a text virtual node.
Source§fn from(value: i32) -> Self
fn from(value: i32) -> Self
Converts this integer into a text virtual node.
OPT 29: i32::to_string() is unavoidable, so the Cow wraps an
Owned variant. (Cow::Owned(text) is implicit via the
String: Into<Cow<'static, str>> bound, but spelled out for
consistency.)
§Returns
VirtualNode- A text virtual node.
§Arguments
i32- Input value to convert from.
Source§impl From<usize> for VirtualNode
Converts a usize into a text virtual node.
impl From<usize> for VirtualNode
Converts a usize into a text virtual node.
Source§impl<T: PartialEq> PartialEq for VirtualNode<T>
Visual equality comparison for virtual DOM nodes.
impl<T: PartialEq> PartialEq for VirtualNode<T>
Visual equality comparison for virtual DOM nodes.
Used by DynamicNode re-rendering to skip unnecessary DOM patches when the rendered output has not changed. Event attributes are always considered equal because re-binding event listeners is handled separately by the handler registry and does not affect visual output. Dynamic nodes manage their own subtree re-rendering, so two Dynamic variants are always considered equal — the inner renderer handles patching when the dynamic content actually changes.