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 try_get_children(&self) -> Option<&Vec<VirtualNode>>
pub fn try_get_children(&self) -> Option<&Vec<VirtualNode>>
Returns a reference to the children of this node, if it has any.
Returns Some for Element and Fragment variants, None otherwise.
§Returns
Option<&Vec<VirtualNode>>- The children, 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_child_node(&self) -> Option<VirtualNode>
pub fn try_get_child_node(&self) -> Option<VirtualNode>
Returns the children of this node as a virtual node.
Returns VirtualNode::Empty when there are no children, a single child
when there is exactly one, or VirtualNode::Fragment when there are
multiple children.
§Returns
Option<VirtualNode>- The children as a virtual node.
Sourcepub fn get_child_node(&self) -> VirtualNode
pub fn get_child_node(&self) -> VirtualNode
Returns the children of this node as a virtual node.
Returns VirtualNode::Empty when there are no children, a single child
when there is exactly one, or VirtualNode::Fragment when there are
multiple children.
§Returns
VirtualNode- The children as a virtual node.
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) -> VirtualNode
pub fn create_dynamic<F>(render_fn: F) -> VirtualNode
Trait Implementations§
Source§impl<T> Clone for VirtualNode<T>where
T: Clone,
Clones a VirtualNode<T> by deep-copying all fields.
impl<T> Clone for VirtualNode<T>where
T: Clone,
Clones a VirtualNode<T> by deep-copying all fields.
Source§fn clone(&self) -> VirtualNode<T>
fn clone(&self) -> VirtualNode<T>
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 for VirtualNode<T>where
T: Debug,
Debug formatting for VirtualNode<T>.
impl<T> Debug for VirtualNode<T>where
T: Debug,
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() -> VirtualNode<T>
fn default() -> VirtualNode<T>
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§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§fn from(render_fn: F) -> VirtualNode
fn from(render_fn: F) -> VirtualNode
Wraps this closure into a VirtualNode::Dynamic with a fresh hook context.
§Returns
VirtualNode- A dynamic virtual node wrapping this closure.
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>>) -> VirtualNode
fn from(nodes: Option<Vec<VirtualNode>>) -> VirtualNode
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>) -> VirtualNode
fn from(node: Option<VirtualNode>) -> VirtualNode
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>) -> VirtualNode
fn from(nodes: Vec<VirtualNode>) -> VirtualNode
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§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 for VirtualNode<T>where
T: PartialEq,
Visual equality comparison for virtual DOM nodes.
impl<T> PartialEq for VirtualNode<T>where
T: PartialEq,
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.
Source§fn eq(&self, other: &VirtualNode<T>) -> bool
fn eq(&self, other: &VirtualNode<T>) -> bool
self and other values to be equal, and is used by ==.