1use super::{BoxDynElement, BoxDynText, BoxDynUncareNode, MaybeDoc, MaybeElement};
2use std::any::Any;
3#[derive(Debug)]
4pub enum INodeType {
5 Element = 1,
6 Text = 3,
7 XMLCDATA = 4,
8 Comment = 8,
9 Document = 9,
10 HTMLDOCTYPE = 10,
11 DocumentFragement = 11,
12 Other = 14,
13}
14
15impl INodeType {
16 pub fn is_element(&self) -> bool {
17 matches!(self, INodeType::Element)
18 }
19}
20
21pub type BoxDynNode<'a> = Box<dyn INodeTrait + 'a>;
22pub enum IEnumTyped<'a> {
23 Element(BoxDynElement<'a>),
24 Text(BoxDynText<'a>),
25 UncareNode(BoxDynUncareNode<'a>),
26}
27
28impl<'a> IEnumTyped<'a> {
29 pub fn into_element(self) -> Option<BoxDynElement<'a>> {
30 match self {
31 IEnumTyped::Element(ele) => Some(ele),
32 _ => None,
33 }
34 }
35 pub fn into_text(self) -> Option<BoxDynText<'a>> {
36 match self {
37 IEnumTyped::Text(ele) => Some(ele),
38 _ => None,
39 }
40 }
41}
42pub trait INodeTrait {
43 fn to_node(self: Box<Self>) -> Box<dyn Any>;
44 fn clone_node<'b>(&self) -> BoxDynNode<'b>;
46 fn typed<'b>(self: Box<Self>) -> IEnumTyped<'b>;
48 fn node_type(&self) -> INodeType;
50 fn parent<'b>(&self) -> MaybeElement<'b>;
52 fn uuid(&self) -> Option<&str>;
54 fn owner_document(&self) -> MaybeDoc;
56 fn root_element<'b>(&self) -> Option<BoxDynElement<'b>> {
58 if let Some(doc) = &self.owner_document() {
59 let root_node = &doc.get_root_node();
60 return Box::new(root_node.clone_node()).typed().into_element();
61 }
62 None
63 }
64 fn text_content(&self) -> &str;
66 fn text(&self) -> &str {
67 self.text_content()
68 }
69 fn set_text(&mut self, content: &str);
70 fn set_html(&mut self, content: &str);
72 fn index(&self) -> usize;
74}