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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use super::{BoxDynElement, BoxDynText, BoxDynUncareNode, MaybeDoc, MaybeElement};
use std::any::Any;
#[derive(Debug)]
pub enum INodeType {
Element = 1,
Text = 3,
XMLCDATA = 4,
Comment = 8,
Document = 9,
HTMLDOCTYPE = 10,
DocumentFragement = 11,
Other = 14,
}
impl INodeType {
pub fn is_element(&self) -> bool {
matches!(self, INodeType::Element)
}
}
pub type BoxDynNode<'a> = Box<dyn INodeTrait + 'a>;
pub enum IEnumTyped<'a> {
Element(BoxDynElement<'a>),
Text(BoxDynText<'a>),
UncareNode(BoxDynUncareNode<'a>),
}
impl<'a> IEnumTyped<'a> {
pub fn into_element(self) -> Option<BoxDynElement<'a>> {
match self {
IEnumTyped::Element(ele) => Some(ele),
_ => None,
}
}
pub fn into_text(self) -> Option<BoxDynText<'a>> {
match self {
IEnumTyped::Text(ele) => Some(ele),
_ => None,
}
}
}
pub trait INodeTrait {
fn to_node(self: Box<Self>) -> Box<dyn Any>;
fn clone_node<'b>(&self) -> BoxDynNode<'b>;
fn typed<'b>(self: Box<Self>) -> IEnumTyped<'b>;
fn node_type(&self) -> INodeType;
fn parent<'b>(&self) -> MaybeElement<'b>;
fn uuid(&self) -> Option<&str>;
fn owner_document(&self) -> MaybeDoc;
fn root_element<'b>(&self) -> Option<BoxDynElement<'b>> {
if let Some(doc) = &self.owner_document() {
let root_node = &doc.get_root_node();
return Box::new(root_node.clone_node()).typed().into_element();
}
None
}
fn text_content(&self) -> &str;
fn text(&self) -> &str {
self.text_content()
}
fn set_text(&mut self, content: &str);
fn set_html(&mut self, content: &str);
fn index(&self) -> usize;
}