1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! ToVNode trait for converting components to VNode
//!
//! This trait allows any UI component to be converted to a VNode,
//! enabling them to be used as children in other components.
use crate::simple_vnode::VNode;
/// Trait for types that can be converted to a VNode
pub trait ToVNode {
/// Convert this component to a VNode
fn to_vnode(self) -> VNode;
}
// Implement for VNode itself (identity conversion)
impl ToVNode for VNode {
fn to_vnode(self) -> VNode {
self
}
}
// Implement for String (text node)
impl ToVNode for String {
fn to_vnode(self) -> VNode {
VNode::Text(self)
}
}
// Implement for &str (text node)
impl ToVNode for &str {
fn to_vnode(self) -> VNode {
VNode::Text(self.to_string())
}
}
// Implement for Vec<VNode> (fragment)
impl ToVNode for Vec<VNode> {
fn to_vnode(self) -> VNode {
// Wrap in a fragment div
VNode::element("div", vec![], self)
}
}