duid_core/core/html/
node.rs

1use super::nodes::{Element, Leaf};
2use crate::core::html::attributes::Attribute;
3
4#[derive(Debug, Clone, PartialEq)]
5pub enum Node<MSG> {
6    Element(Element<MSG>),
7    Fragment(Vec<Node<MSG>>),
8    Text(Leaf<MSG>),
9    Comment(Leaf<MSG>),
10    DocType(Leaf<MSG>),
11}
12
13impl<MSG> Node<MSG> {
14
15    pub fn extend_attrs(&mut self, attrs: impl IntoIterator<Item = Attribute<MSG>>) {
16        match self {
17            Node::Element(e) => {e.props.extend(attrs);},
18            Node::Fragment(_) => {},
19            Node::Text(t) => {t.props.extend(attrs);},
20            Node::Comment(c) => {c.props.extend(attrs);},
21            Node::DocType(d) => {d.props.extend(attrs);},
22        }
23    }
24
25    pub fn extend_children(&mut self, children: impl IntoIterator<Item = Node<MSG>>) {
26        match self {
27            Node::Element(e) => {e.children.extend(children);},
28            _ => {},
29        }
30    }
31}