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>

Returns a reference to the props of this node, if it has any.

Only Element variants with component tags carry props.

§Returns
  • Option<&T> - The props reference, or None.
Source

pub fn try_take_props(&mut self) -> Option<T>

Takes the props out of this node, leaving None in its place.

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

pub fn take_children(&mut self) -> VirtualNode

Takes the children out of this node, replacing them with an empty vector.

Returns a VirtualNode (Fragment or single child) representation of the 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) -> Self
where F: FnMut() -> Self + 'static,

Constructs a Self::Dynamic from a render closure with hook context management.

§Arguments
  • FnMut() -> Self + 'static - The render closure that produces a virtual node tree. Called on initial render and on every signal update.
§Returns
  • Self - A Self::Dynamic wrapping the render closure with a fresh HookContext.
Source

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

Constructs a Self::Dynamic for match expressions where arm hook isolation is required. The render closure receives a &mut HookContext so it can call set_arm_changed before each arm body.

§Arguments
  • FnMut(&mut HookContext) -> Self + 'static - The render closure that receives a mutable reference to the hook context.
§Returns
  • Self - A Self::Dynamic wrapping the render closure with a fresh HookContext.

Trait Implementations§

Source§

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

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

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

Debug formatting for VirtualNode<T>.

Skips Dynamic inner details and props for brevity.

Source§

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

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

impl<T> Default for VirtualNode<T>

Default implementation returns VirtualNode::Empty.

Source§

fn default() -> Self

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

impl IntoNode for VirtualNode

Converts a VirtualNode into itself via IntoNode.

Source§

fn into_node(self) -> VirtualNode

Returns this virtual node as-is.

§Returns
  • VirtualNode - This same virtual node.
Source§

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.

Source§

fn eq(&self, other: &Self) -> 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> Freeze for VirtualNode<T>

§

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

§

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

§

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

§

impl<T> Unpin for VirtualNode<T>

§

impl<T> UnsafeUnpin for VirtualNode<T>

§

impl<T = ()> !UnwindSafe 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: 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: ErasableGeneric<Repr = Self::Repr>,

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