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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use atom::Atom;
use std::fmt;
use std::ops;
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Default)]
pub struct Namespace(pub Atom);
#[cfg(feature = "heapsize")]
known_heap_size!(0, Namespace);
pub struct BorrowedNamespace<'a>(pub &'a Namespace);
impl<'a> ops::Deref for BorrowedNamespace<'a> {
type Target = Namespace;
fn deref(&self) -> &Namespace {
self.0
}
}
impl<'a> PartialEq<Namespace> for BorrowedNamespace<'a> {
fn eq(&self, other: &Namespace) -> bool {
self.0 == other
}
}
impl fmt::Display for Namespace {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<str as fmt::Display>::fmt(&self.0, f)
}
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)]
pub struct QualName {
pub ns: Namespace,
pub local: Atom,
}
#[cfg(feature = "heapsize")]
known_heap_size!(0, QualName);
impl QualName {
#[inline]
pub fn new(ns: Namespace, local: Atom) -> QualName {
QualName {
ns: ns,
local: local,
}
}
}
#[cfg(test)]
mod tests {
use super::{Namespace, QualName};
use Atom;
#[test]
fn ns_macro() {
assert_eq!(ns!(), Namespace(Atom::from("")));
assert_eq!(ns!(html), Namespace(Atom::from("http://www.w3.org/1999/xhtml")));
assert_eq!(ns!(xml), Namespace(Atom::from("http://www.w3.org/XML/1998/namespace")));
assert_eq!(ns!(xmlns), Namespace(Atom::from("http://www.w3.org/2000/xmlns/")));
assert_eq!(ns!(xlink), Namespace(Atom::from("http://www.w3.org/1999/xlink")));
assert_eq!(ns!(svg), Namespace(Atom::from("http://www.w3.org/2000/svg")));
assert_eq!(ns!(mathml), Namespace(Atom::from("http://www.w3.org/1998/Math/MathML")));
}
#[test]
fn qualname() {
assert_eq!(QualName::new(ns!(), atom!("")),
QualName { ns: ns!(), local: Atom::from("") });
assert_eq!(QualName::new(ns!(xml), atom!("base")),
QualName { ns: ns!(xml), local: atom!("base") });
}
#[test]
fn qualname_macro() {
assert_eq!(qualname!("", ""), QualName { ns: ns!(), local: atom!("") });
assert_eq!(qualname!(xml, "base"), QualName { ns: ns!(xml), local: atom!("base") });
}
}