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
//! Error management module

#![allow(missing_docs)]

/// The error type used by this crate.
#[cfg_attr(feature = "failure", derive(Fail))]
#[derive(Display, Debug)]
pub enum Error {
    #[display(fmt = "I/O error: {}", "_0")]
    Io(#[cfg_attr(feature = "failure", cause)] ::std::io::Error),

    #[display(fmt = "UTF8 error: {}", "_0")]
    Utf8(#[cfg_attr(feature = "failure", cause)] ::std::str::Utf8Error),

    #[display(fmt = "Unexpected EOF during reading {}.", "_0")]
    UnexpectedEof(String),

    #[display(fmt = "Expecting </{}> found </{}>", expected, found)]
    EndEventMismatch { expected: String, found: String },

    #[display(fmt = "Unexpected token '{}'", "_0")]
    UnexpectedToken(String),

    #[display(fmt = "Only Comment, CDATA and DOCTYPE nodes can start with a '!'")]
    UnexpectedBang,

    #[display(fmt = "Cannot read text, expecting Event::Text")]
    TextNotFound,

    #[display(fmt = "XmlDecl must start with 'version' attribute, found {:?}", "_0")]
    XmlDeclWithoutVersion(Option<String>),

    #[display(
        fmt = "error while parsing attribute at position {}: Attribute key cannot contain quote.",
        "_0"
    )]
    NameWithQuote(usize),

    #[display(
        fmt = "error while parsing attribute at position {}: Attribute key must be directly followed by = or space",
        "_0"
    )]
    NoEqAfterName(usize),

    #[display(
        fmt = "error while parsing attribute at position {}: Attribute value must start with a quote.",
        "_0"
    )]
    UnquotedValue(usize),

    #[display(
        fmt = "error while parsing attribute at position {}: Duplicate attribute at position {} and {}",
        "_0",
        "_1",
        "_0"
    )]
    DuplicatedAttribute(usize, usize),

    #[display(fmt = "{}", "_0")]
    EscapeError(#[cfg_attr(feature = "failure", cause)] ::escape::EscapeError),
}

impl From<::std::io::Error> for Error {
    /// Creates a new `Error::Io` from the given error
    #[inline]
    fn from(error: ::std::io::Error) -> Error {
        Error::Io(error)
    }
}

impl From<::std::str::Utf8Error> for Error {
    /// Creates a new `Error::Utf8` from the given error
    #[inline]
    fn from(error: ::std::str::Utf8Error) -> Error {
        Error::Utf8(error)
    }
}

/// A specialized `Result` type where the error is hard-wired to [`Error`].
///
/// [`Error`]: enum.Error.html
pub type Result<T> = ::std::result::Result<T, Error>;