1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
mod display;
use std::{
collections::{btree_map, BTreeMap},
slice,
};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SVG {
element: &'static str,
attributes: BTreeMap<&'static str, String>,
children: Vec<SVG>,
}
impl SVG {
pub fn new(element: &'static str, attributes: Vec<(&'static str, String)>, children: Vec<SVG>) -> Self {
Self { element, attributes: BTreeMap::from_iter(attributes.into_iter()), children }
}
pub fn insert_attribute<S>(&mut self, keys: &'static str, value: S)
where
S: Into<String>,
{
self.attributes.insert(keys, value.into());
}
pub fn attributes(&self) -> btree_map::Iter<'_, &'static str, String> {
self.attributes.iter()
}
pub fn attributes_mut(&mut self) -> btree_map::IterMut<'_, &'static str, String> {
self.attributes.iter_mut()
}
pub fn insert_child(&mut self, child: SVG) {
self.children.push(child);
}
pub fn children(&self) -> slice::Iter<'_, SVG> {
self.children.iter()
}
pub fn children_mut(&mut self) -> slice::IterMut<'_, SVG> {
self.children.iter_mut()
}
}