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 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 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.
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<&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§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§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.