error.rs

 1//! Provides an error type for this crate.
 2
 3use std::convert::From;
 4
 5/// Our main error type.
 6#[derive(Debug, Fail)]
 7pub enum Error {
 8    /// An error from quick_xml.
 9    #[fail(display = "XML error: {}", _0)]
10    XmlError(#[cause] ::quick_xml::Error),
11
12    /// An UTF-8 conversion error.
13    #[fail(display = "UTF-8 error: {}", _0)]
14    Utf8Error(#[cause] ::std::str::Utf8Error),
15
16    /// An I/O error, from std::io.
17    #[fail(display = "IO error: {}", _0)]
18    IoError(#[cause] ::std::io::Error),
19
20    /// An error which is returned when the end of the document was reached prematurely.
21    #[fail(display = "the end of the document has been reached prematurely")]
22    EndOfDocument,
23
24    /// An error which is returned when an element is closed when it shouldn't be
25    #[fail(display = "the XML is invalid, an element was wrongly closed")]
26    InvalidElementClosed,
27
28    /// An error which is returned when an elemet's name contains more than one colon
29    #[fail(display = "the XML element is invalid")]
30    InvalidElement,
31}
32
33impl From<::quick_xml::Error> for Error {
34    fn from(err: ::quick_xml::Error) -> Error {
35        Error::XmlError(err)
36    }
37}
38
39impl From<::std::str::Utf8Error> for Error {
40    fn from(err: ::std::str::Utf8Error) -> Error {
41        Error::Utf8Error(err)
42    }
43}
44
45impl From<::std::io::Error> for Error {
46    fn from(err: ::std::io::Error) -> Error {
47        Error::IoError(err)
48    }
49}
50
51/// Our simplified Result type.
52pub type Result<T> = ::std::result::Result<T, Error>;