Skip to main content

VirtualNode

Enum VirtualNode 

Source
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

§tag: Tag

The tag type of this element.

§attributes: Vec<AttributeEntry>

The attributes attached to this element.

§children: Vec<VirtualNode>

The child nodes.

§key: Option<String>

An optional key for diffing.

§props: Option<Box<T>>

The component props, present only for component 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.

Source

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, or None if not an element.
Source

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, or None.
Source

pub fn has_children(&self) -> bool

Returns true if this node has non-empty children.

§Returns
  • bool - Whether this node has children.
Source

pub fn try_get_props(&self) -> Option<T>
where T: Clone,

Clones the props of this node.

§Returns
  • Option<T> - The cloned props, or None if this node has no props.
Source

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

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

Source

pub fn create_dynamic<F>(render_fn: F) -> VirtualNode
where F: FnMut(&mut HookContext) -> VirtualNode + 'static,

Creates a dynamic node with the given render function.

§Arguments
  • F: FnMut(&mut HookContext) -> Self + 'static - The render function.
§Returns
  • Self - The dynamic node.

Trait Implementations§

Source§

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

Clones a VirtualNode<T> by deep-copying all fields.

Source§

fn clone(&self) -> VirtualNode<T>

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<T> Debug for VirtualNode<T>
where T: Debug,

Debug formatting for VirtualNode<T>.

Skips Dynamic inner details and props for brevity.

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for VirtualNode<T>

Default implementation returns VirtualNode::Empty.

Source§

fn default() -> VirtualNode<T>

Returns the “default value” for a type. Read more
Source§

impl From<&str> for VirtualNode

Converts a &str into a text virtual node.

Source§

fn from(text: &str) -> VirtualNode

Converts this string slice into a text virtual node.

§Returns
  • VirtualNode - A text virtual node.
Source§

impl<F> From<F> for VirtualNode
where F: FnMut(&mut HookContext) -> VirtualNode + 'static,

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

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.

Some(vec) converts the vector into a VirtualNode::Fragment (or Empty if the vector is empty), None returns VirtualNode::Empty.

§Returns

  • VirtualNode - A VirtualNode::Fragment if Some with nodes, VirtualNode::Empty if None or the vector is empty.
Source§

fn from(nodes: Option<Vec<VirtualNode>>) -> VirtualNode

Converts to this type from the input type.
Source§

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 if Some, otherwise VirtualNode::Empty.
Source§

fn from(node: Option<VirtualNode>) -> VirtualNode

Converts to this type from the input type.
Source§

impl<T> From<Signal<T>> for VirtualNode
where T: Clone + PartialEq + Display + 'static,

Converts a signal into a reactive text virtual node.

Source§

fn from(signal: Signal<T>) -> VirtualNode

Converts this signal into a reactive text virtual node.

§Returns
  • VirtualNode - A reactive text virtual node.
Source§

impl From<String> for VirtualNode

Converts a String into a text virtual node.

Source§

fn from(text: String) -> VirtualNode

Converts this string into a text virtual node.

§Returns
  • VirtualNode - A text virtual node.
Source§

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 - A VirtualNode::Fragment containing the nodes, or VirtualNode::Empty if the vector is empty.
Source§

fn from(nodes: Vec<VirtualNode>) -> VirtualNode

Converts to this type from the input type.
Source§

impl From<bool> for VirtualNode

Converts a bool into a text virtual node.

Source§

fn from(value: bool) -> VirtualNode

Converts this boolean into a text virtual node.

§Returns
  • VirtualNode - A text virtual node.
Source§

impl From<i32> for VirtualNode

Converts an i32 into a text virtual node.

Source§

fn from(value: i32) -> VirtualNode

Converts this integer into a text virtual node.

§Returns
  • VirtualNode - A text virtual node.
Source§

impl From<usize> for VirtualNode

Converts a usize into a text virtual node.

Source§

fn from(value: usize) -> VirtualNode

Converts this unsigned integer into a text virtual node.

§Returns
  • VirtualNode - A text virtual node.
Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T = ()> !RefUnwindSafe for VirtualNode<T>

§

impl<T = ()> !Send for VirtualNode<T>

§

impl<T = ()> !Sync for VirtualNode<T>

§

impl<T = ()> !UnwindSafe for VirtualNode<T>

§

impl<T> Freeze for VirtualNode<T>

§

impl<T> Unpin for VirtualNode<T>

§

impl<T> UnsafeUnpin for VirtualNode<T>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more