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
use std::convert::From;
#[derive(Debug)]
pub enum Error {
XmlError(::quick_xml::Error),
Utf8Error(::std::str::Utf8Error),
IoError(::std::io::Error),
EndOfDocument,
InvalidElementClosed,
InvalidElement,
#[cfg(not(comments))]
CommentsDisabled,
}
impl std::fmt::Display for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::XmlError(e) => write!(fmt, "XML error: {}", e),
Error::Utf8Error(e) => write!(fmt, "UTF-8 error: {}", e),
Error::IoError(e) => write!(fmt, "IO error: {}", e),
Error::EndOfDocument => write!(fmt, "the end of the document has been reached prematurely"),
Error::InvalidElementClosed => write!(fmt, "the XML is invalid, an element was wrongly closed"),
Error::InvalidElement => write!(fmt, "the XML element is invalid"),
#[cfg(not(comments))]
Error::CommentsDisabled => write!(fmt, "a comment has been found even though comments are disabled by feature"),
}
}
}
impl From<::quick_xml::Error> for Error {
fn from(err: ::quick_xml::Error) -> Error {
Error::XmlError(err)
}
}
impl From<::std::str::Utf8Error> for Error {
fn from(err: ::std::str::Utf8Error) -> Error {
Error::Utf8Error(err)
}
}
impl From<::std::io::Error> for Error {
fn from(err: ::std::io::Error) -> Error {
Error::IoError(err)
}
}
pub type Result<T> = ::std::result::Result<T, Error>;