Enum dioxus_core::prelude::VNode
source · [−]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:
- the
rsx!
macro - the
NodeFactory
API
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
sourceimpl<'src> VNode<'src>
impl<'src> VNode<'src>
sourcepub fn key(&self) -> Option<&'src str>
pub fn key(&self) -> Option<&'src str>
Get the VNode’s “key” used in the keyed diffing algorithm.
sourcepub fn mounted_id(&self) -> ElementId
pub fn mounted_id(&self) -> ElementId
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.
sourcepub fn try_mounted_id(&self) -> Option<ElementId>
pub fn try_mounted_id(&self) -> Option<ElementId>
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
sourceimpl<'a> IntoIterator for VNode<'a>
impl<'a> IntoIterator for VNode<'a>
sourceimpl<'a> IntoVNode<'a> for VNode<'a>
impl<'a> IntoVNode<'a> for VNode<'a>
sourcefn into_vnode(self, _: NodeFactory<'a>) -> VNode<'a>
fn into_vnode(self, _: NodeFactory<'a>) -> VNode<'a>
Convert this into a VNode
, using the NodeFactory
as a source of allocation
sourceimpl<'a> IntoVNode<'a> for &VNode<'a>
impl<'a> IntoVNode<'a> for &VNode<'a>
sourcefn into_vnode(self, _cx: NodeFactory<'a>) -> VNode<'a>
fn into_vnode(self, _cx: NodeFactory<'a>) -> VNode<'a>
Convert this into a VNode
, using the NodeFactory
as a source of allocation
Auto Trait Implementations
impl<'src> !RefUnwindSafe for VNode<'src>
impl<'src> !Send for VNode<'src>
impl<'src> !Sync for VNode<'src>
impl<'src> Unpin for VNode<'src>
impl<'src> !UnwindSafe for VNode<'src>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more