serde_html/traits/
edit.rs1
2use super::*;
3
4impl Default for HtmlElement {
5 fn default() -> Self {
6 HtmlElement {
7 tag: Default::default(),
8 classes: IndexSet::default(),
9 attributes: Default::default(),
10 children: vec![],
11 }
12 }
13}
14
15impl Element for HtmlElement {
16 fn build(self) -> HtmlElement {
17 self
18 }
19
20 fn get_tag(&self) -> &str {
21 &self.tag
22 }
23 fn set_tag<S>(&mut self, tag: S) -> bool where S: Into<Cow<'static, str>> {
24 self.tag = tag.into();
25 true
26 }
27 fn get_attribute(&self, name: &str) -> Option<&AttributeValue> {
28 self.attributes.get(name)
29 }
30 fn mut_attribute(&mut self, name: &str) -> Option<&mut AttributeValue> {
31 self.attributes.get_mut(name)
32 }
33 fn set_attribute<S>(&mut self, name: S, value: AttributeValue) -> bool where S: Into<Cow<'static, str>> {
34 self.attributes.insert(name.into(), value);
35 true
36 }
37 fn get_classes(&self) -> impl Iterator<Item=&str> {
38 self.classes.iter().map(|s| s.as_ref())
39 }
40 fn set_classes<I>(&mut self, classes: I) -> bool where I: Iterator<Item=Cow<'static, str>> {
41 self.classes = classes.collect();
42 true
43 }
44 fn add_class<S>(&mut self, class: S) -> bool where S: Into<Cow<'static, str>> {
45 self.classes.insert(class.into())
46 }
47 fn remove_class<S>(&mut self, class: &str) -> bool {
48 self.classes.remove(class)
49 }
50 fn add_child<T>(&mut self, child: T) -> bool where T: Into<HtmlNode> {
51 self.children.push(child.into());
52 true
53 }
54 fn get_children(&self) -> impl Iterator<Item=&HtmlNode> {
55 self.children.iter()
56 }
57 fn mut_children(&mut self) -> impl Iterator<Item=&mut HtmlNode> {
58 self.children.iter_mut()
59 }
60 fn set_children<I>(&mut self, children: I) -> bool where I: Iterator<Item=HtmlNode> {
61 self.children = children.collect();
62 true
63 }
64}