Skip to main content

react_rs_elements/
node.rs

1use crate::reactive::ReactiveValue;
2use crate::Element;
3
4pub enum Node {
5    Element(Element),
6    Text(String),
7    ReactiveText(ReactiveValue<String>),
8    Fragment(Vec<Node>),
9}
10
11pub trait IntoNode {
12    fn into_node(self) -> Node;
13}
14
15impl IntoNode for Element {
16    fn into_node(self) -> Node {
17        Node::Element(self)
18    }
19}
20
21impl IntoNode for String {
22    fn into_node(self) -> Node {
23        Node::Text(self)
24    }
25}
26
27impl IntoNode for &str {
28    fn into_node(self) -> Node {
29        Node::Text(self.to_string())
30    }
31}
32
33impl<T: IntoNode> IntoNode for Vec<T> {
34    fn into_node(self) -> Node {
35        Node::Fragment(self.into_iter().map(|n| n.into_node()).collect())
36    }
37}
38
39impl IntoNode for Node {
40    fn into_node(self) -> Node {
41        self
42    }
43}