sycamore::web

Trait ViewNode

pub trait ViewNode:
    Sized
    + Into<View<Self>>
    + 'static {
    // Required method
    fn append_child(&mut self, child: Self);

    // Provided methods
    fn append_view(&mut self, view: View<Self>) { ... }
    fn create_dynamic_view<U>(f: impl FnMut() -> U + 'static) -> View<Self>
       where U: Into<View<Self>> + 'static { ... }
}
Expand description

A trait that should be implemented for anything that represents a node in the view tree (UI tree).

Examples include DomNode and SsrNode which are used to render views to the browser DOM and to a string respectively. This trait can be implemented for other types to create custom render backends.

Required Methods§

fn append_child(&mut self, child: Self)

Appends a child to the node. Panics if the node is not an element or other node that can have children (e.g. text node).

Provided Methods§

fn append_view(&mut self, view: View<Self>)

Append a view to this node. Since a view is just a list of nodes, this essentially appends every node in the view to this node.

fn create_dynamic_view<U>(f: impl FnMut() -> U + 'static) -> View<Self>
where U: Into<View<Self>> + 'static,

Create a dynamic view from a function that returns a view.

The returned view will no longer be a function and can be treated as a normal view and, e.g., appended as a child to another node.

Some render backends may not support dynamic views (e.g. SsrNode). In that case, the default behavior is to simply evaluate the function as a static view.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§