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
use crate::level2::ext::namespaced::MutNamespaced;
use crate::level2::ext::traits::*;
use crate::level2::node_impl::*;
use crate::level2::traits::NodeType;
use crate::shared::error::{Error, Result, MSG_INVALID_NODE_TYPE};
use crate::{make_is_as_functions, make_ref_type};
make_ref_type!(RefDocumentDecl, MutRefDocumentDecl, DocumentDecl);
make_ref_type!(RefNamespaced, Namespaced);
pub(crate) type MutRefNamespaced<'a> = &'a mut dyn MutNamespaced<NodeRef = RefNode>;
make_is_as_functions!(
is_document_decl,
NodeType::Document,
as_document_decl,
RefDocumentDecl,
as_document_decl_mut,
MutRefDocumentDecl
);
make_is_as_functions!(
is_element_namespaced,
NodeType::Element,
as_element_namespaced,
RefNamespaced
);
#[inline]
pub(crate) fn as_element_namespaced_mut(ref_node: &mut RefNode) -> Result<MutRefNamespaced<'_>> {
if ref_node.borrow().i_node_type == NodeType::Element {
Ok(ref_node as MutRefNamespaced<'_>)
} else {
warn!("{}", MSG_INVALID_NODE_TYPE);
Err(Error::InvalidState)
}
}