use std::collections::HashMap; pub trait Component { fn render(self: Box) -> Vec; } pub enum RenderNode { Component(Box), Element { name: String, attributes: HashMap, children: Vec }, TextNode { content: String, }, Portal, Null, } impl RenderNode { pub(crate) fn render_to_string(self) -> String { match self { RenderNode::Component(component) => { let elements = component.render(); elements.into_iter() .map(|child| child.render_to_string()) .collect::>().join("") }, RenderNode::Element { name, attributes, children } => { let text_attributes = attributes.into_iter() .map(|(key, value)| format!(" {key}=\"{value}\"")) .collect::>().join(""); let rendered_children = children.into_iter() .map(|child| child.render_to_string()) .collect::>().join(""); format!("<{name}{text_attributes}>{rendered_children}") }, RenderNode::TextNode { content } => content, RenderNode::Portal => todo!(), RenderNode::Null => "".to_string(), } } }