Remove failure.
This commit is contained in:
parent
ea88adbafb
commit
b4035d1227
3 changed files with 19 additions and 15 deletions
|
@ -21,8 +21,6 @@ gitlab = { repository = "lumi/minidom-rs" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quick-xml = "0.15"
|
quick-xml = "0.15"
|
||||||
failure = "0.1.1"
|
|
||||||
failure_derive = "0.1.1"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["comments"]
|
default = ["comments"]
|
||||||
|
|
30
src/error.rs
30
src/error.rs
|
@ -3,38 +3,46 @@
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
/// Our main error type.
|
/// Our main error type.
|
||||||
#[derive(Debug, Fail)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// An error from quick_xml.
|
/// An error from quick_xml.
|
||||||
#[fail(display = "XML error: {}", _0)]
|
XmlError(::quick_xml::Error),
|
||||||
XmlError(#[cause] ::quick_xml::Error),
|
|
||||||
|
|
||||||
/// An UTF-8 conversion error.
|
/// An UTF-8 conversion error.
|
||||||
#[fail(display = "UTF-8 error: {}", _0)]
|
Utf8Error(::std::str::Utf8Error),
|
||||||
Utf8Error(#[cause] ::std::str::Utf8Error),
|
|
||||||
|
|
||||||
/// An I/O error, from std::io.
|
/// An I/O error, from std::io.
|
||||||
#[fail(display = "IO error: {}", _0)]
|
IoError(::std::io::Error),
|
||||||
IoError(#[cause] ::std::io::Error),
|
|
||||||
|
|
||||||
/// An error which is returned when the end of the document was reached prematurely.
|
/// An error which is returned when the end of the document was reached prematurely.
|
||||||
#[fail(display = "the end of the document has been reached prematurely")]
|
|
||||||
EndOfDocument,
|
EndOfDocument,
|
||||||
|
|
||||||
/// An error which is returned when an element is closed when it shouldn't be
|
/// An error which is returned when an element is closed when it shouldn't be
|
||||||
#[fail(display = "the XML is invalid, an element was wrongly closed")]
|
|
||||||
InvalidElementClosed,
|
InvalidElementClosed,
|
||||||
|
|
||||||
/// An error which is returned when an elemet's name contains more than one colon
|
/// An error which is returned when an elemet's name contains more than one colon
|
||||||
#[fail(display = "the XML element is invalid")]
|
|
||||||
InvalidElement,
|
InvalidElement,
|
||||||
|
|
||||||
/// An error which is returned when a comment is to be parsed by minidom
|
/// An error which is returned when a comment is to be parsed by minidom
|
||||||
#[cfg(not(comments))]
|
#[cfg(not(comments))]
|
||||||
#[fail(display = "a comment has been found even though comments are disabled by feature")]
|
|
||||||
CommentsDisabled,
|
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 {
|
impl From<::quick_xml::Error> for Error {
|
||||||
fn from(err: ::quick_xml::Error) -> Error {
|
fn from(err: ::quick_xml::Error) -> Error {
|
||||||
Error::XmlError(err)
|
Error::XmlError(err)
|
||||||
|
|
|
@ -65,8 +65,6 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
extern crate quick_xml;
|
extern crate quick_xml;
|
||||||
extern crate failure;
|
|
||||||
#[macro_use] extern crate failure_derive;
|
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod element;
|
pub mod element;
|
||||||
|
|
Loading…
Reference in a new issue