Skip to main content

euv_core/vdom/
trait.rs

1use crate::*;
2
3/// Trait for types that can be converted into a `VirtualNode` for use in HTML expressions.
4///
5/// Implemented by primitive types, strings, and signals to allow seamless
6/// embedding in HTML markup.
7pub trait AsNode {
8    /// Converts this value into a `VirtualNode`, if possible.
9    fn as_node(&self) -> Option<VirtualNode>;
10}
11
12/// Trait for types that can be converted into a reactive text `VirtualNode`.
13///
14/// Signals implement this to produce a text node that auto-updates.
15pub trait AsReactiveText {
16    /// Converts this value into a `VirtualNode::Text` with reactive signal binding.
17    fn as_reactive_text(&self) -> VirtualNode;
18}
19
20/// Trait for converting a value into a `VirtualNode` by consuming it.
21///
22/// Unlike `AsNode` which borrows `&self`, this trait takes ownership,
23/// enabling closures to be wrapped into `DynamicNode` for reactive re-rendering.
24pub trait IntoNode {
25    /// Converts this value into a `VirtualNode` by consuming it.
26    fn into_node(self) -> VirtualNode;
27}