Debian Codegraph @

src/node/mod.rs

raw symbols SCIP
1 //! The nodes.
2
3 use std::collections::hash_map::DefaultHasher;
4 use std::collections::HashMap;
5 use std::fmt;
6
7 mod blob;
8 mod comment;
9 mod text;
10 mod value;
11
12 pub use self::blob::Blob;
13 pub use self::comment::Comment;
14 pub use self::text::Text;
15 pub use self::value::Value;
16
17 /// Attributes.
18 pub type Attributes = HashMap<String, Value>;
19
20 /// Child nodes.
21 pub type Children = Vec<Box<dyn Node>>;
22
23 /// A node.
24 pub trait Node:
25 'static + fmt::Debug + fmt::Display + NodeClone + NodeDefaultHash + Send + Sync
26 {
27 /// Append a child node.
28 #[inline]
29 fn append<T>(&mut self, _: T)
30 where
31 Self: Sized,
32 T: Into<Box<dyn Node>>,
33 {
34 }
35
36 /// Assign an attribute.
37 #[inline]
38 fn assign<T, U>(&mut self, _: T, _: U)
39 where
40 Self: Sized,
41 T: Into<String>,
42 U: Into<Value>,
43 {
44 }
45
46 /// Return the name.
47 fn get_name(&self) -> &str;
48
49 /// Return the attributes.
50 #[inline]
51 fn get_attributes(&self) -> Option<&Attributes> {
52 None
53 }
54
55 /// Return the attributes as mutable.
56 fn get_attributes_mut(&mut self) -> Option<&mut Attributes> {
57 None
58 }
59
60 /// Return the children.
61 fn get_children(&self) -> Option<&Children> {
62 None
63 }
64
65 /// Return the children as mutable.
66 fn get_children_mut(&mut self) -> Option<&mut Children> {
67 None
68 }
69
70 #[doc(hidden)]
71 fn is_bare(&self) -> bool {
72 false
73 }
74
75 #[doc(hidden)]
76 fn is_bareable(&self) -> bool {
77 false
78 }
79 }
80
81 #[doc(hidden)]
82 pub trait NodeClone {
83 fn clone(&self) -> Box<dyn Node>;
84 }
85
86 #[doc(hidden)]
87 pub trait NodeDefaultHash {
88 fn default_hash(&self, state: &mut DefaultHasher);
89 }
90
91 impl<T> NodeClone for T
92 where
93 T: Node + Clone,
94 {
95 #[inline]
96 fn clone(&self) -> Box<dyn Node> {
97 Box::new(Clone::clone(self))
98 }
99 }
100
101 impl Clone for Box<dyn Node> {
102 #[inline]
103 fn clone(&self) -> Self {
104 NodeClone::clone(&**self)
105 }
106 }
107
108 impl<T> From<T> for Box<dyn Node>
109 where
110 T: Node,
111 {
112 #[inline]
113 fn from(node: T) -> Box<dyn Node> {
114 Box::new(node)
115 }
116 }
117
118 impl NodeDefaultHash for Box<dyn Node> {
119 #[inline]
120 fn default_hash(&self, state: &mut DefaultHasher) {
121 NodeDefaultHash::default_hash(&**self, state)
122 }
123 }
124
125 pub mod element;