muffy_document/html/
element.rs1use super::node::Node;
2use alloc::sync::Arc;
3use core::ops::Deref;
4
5#[derive(Debug, Eq, PartialEq)]
7pub struct Element {
8 name: String,
9 attributes: Vec<(String, String)>,
10 children: Vec<Arc<Node>>,
11}
12
13impl Element {
14 pub const fn new(
16 name: String,
17 attributes: Vec<(String, String)>,
18 children: Vec<Arc<Node>>,
19 ) -> Self {
20 Self {
21 name,
22 attributes,
23 children,
24 }
25 }
26
27 pub fn name(&self) -> &str {
29 &self.name
30 }
31
32 pub fn attributes(&self) -> impl Iterator<Item = (&str, &str)> {
34 self.attributes
35 .iter()
36 .map(|(key, value)| (key.as_str(), value.as_str()))
37 }
38
39 pub fn children(&self) -> impl Iterator<Item = &Node> {
41 self.children.iter().map(Deref::deref)
42 }
43}
44
45impl From<Element> for Node {
46 fn from(element: Element) -> Self {
47 Self::Element(element)
48 }
49}