pub enum VNode<'src> {
    Text(&'src VText<'src>),
    Element(&'src VElement<'src>),
    Fragment(&'src VFragment<'src>),
    Component(&'src VComponent<'src>),
    Placeholder(&'src VPlaceholder),
}
Expand description

A composable “VirtualNode” to declare a User Interface in the Dioxus VirtualDOM.

VNodes are designed to be lightweight and used with with a bump allocator. To create a VNode, you can use either of:

Variants

Text(&'src VText<'src>)

Text VNodes are simply bump-allocated (or static) string slices

Example

let mut vdom = VirtualDom::new();
let node = vdom.render_vnode(rsx!( "hello" ));

if let VNode::Text(vtext) = node {
    assert_eq!(vtext.text, "hello");
    assert_eq!(vtext.dom_id.get(), None);
    assert_eq!(vtext.is_static, true);
}

Element(&'src VElement<'src>)

Element VNodes are VNodes that may contain attributes, listeners, a key, a tag, and children.

Example

let mut vdom = VirtualDom::new();

let node = vdom.render_vnode(rsx!{
    div {
        key: "a",
        onclick: |e| log::info!("clicked"),
        hidden: "true",
        style: { background_color: "red" },
        "hello"
    }
});

if let VNode::Element(velement) = node {
    assert_eq!(velement.tag_name, "div");
    assert_eq!(velement.namespace, None);
    assert_eq!(velement.key, Some("a"));
}

Fragment(&'src VFragment<'src>)

Fragment nodes may contain many VNodes without a single root.

Example

rsx!{
    a {}
    link {}
    style {}
    "asd"
    Example {}
}

Component(&'src VComponent<'src>)

Component nodes represent a mounted component with props, children, and a key.

Example

fn Example(cx: Scope) -> Element {
    ...
}

let mut vdom = VirtualDom::new();

let node = vdom.render_vnode(rsx!( Example {} ));

if let VNode::Component(vcomp) = node {
    assert_eq!(vcomp.user_fc, Example as *const ());
}

Placeholder(&'src VPlaceholder)

Placeholders are a type of placeholder VNode used when fragments don’t contain any children.

Placeholders cannot be directly constructed via public APIs.

Example

let mut vdom = VirtualDom::new();

let node = vdom.render_vnode(rsx!( Fragment {} ));

if let VNode::Fragment(frag) = node {
    let root = &frag.children[0];
    assert_eq!(root, VNode::Anchor);
}

Implementations

Get the VNode’s “key” used in the keyed diffing algorithm.

Get the ElementID of the mounted VNode.

Panics if the mounted ID is None or if the VNode is not represented by a single Element.

Try to get the ElementID of the mounted VNode.

Returns None if the VNode is not mounted, or if the VNode cannot be presented by a mounted ID (Fragment/Component)

Trait Implementations

Formats the value using the given formatter. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Convert this into a VNode, using the NodeFactory as a source of allocation

Convert this into a VNode, using the NodeFactory as a source of allocation

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.