From b4035d122738e107d7f95c230ec3260026867e79 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 5 Sep 2019 20:06:17 +0200 Subject: [PATCH] Remove failure. --- Cargo.toml | 2 -- src/error.rs | 30 +++++++++++++++++++----------- src/lib.rs | 2 -- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9ed80d59..4e1632aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,6 @@ gitlab = { repository = "lumi/minidom-rs" } [dependencies] quick-xml = "0.15" -failure = "0.1.1" -failure_derive = "0.1.1" [features] default = ["comments"] diff --git a/src/error.rs b/src/error.rs index 773f214f..fc96a08b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,38 +3,46 @@ use std::convert::From; /// Our main error type. -#[derive(Debug, Fail)] +#[derive(Debug)] pub enum Error { /// An error from quick_xml. - #[fail(display = "XML error: {}", _0)] - XmlError(#[cause] ::quick_xml::Error), + XmlError(::quick_xml::Error), /// An UTF-8 conversion error. - #[fail(display = "UTF-8 error: {}", _0)] - Utf8Error(#[cause] ::std::str::Utf8Error), + Utf8Error(::std::str::Utf8Error), /// An I/O error, from std::io. - #[fail(display = "IO error: {}", _0)] - IoError(#[cause] ::std::io::Error), + IoError(::std::io::Error), /// 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, /// 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, /// An error which is returned when an elemet's name contains more than one colon - #[fail(display = "the XML element is invalid")] InvalidElement, /// An error which is returned when a comment is to be parsed by minidom #[cfg(not(comments))] - #[fail(display = "a comment has been found even though comments are disabled by feature")] 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) diff --git a/src/lib.rs b/src/lib.rs index 5ea7e706..cf17cdac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,8 +65,6 @@ //! ``` extern crate quick_xml; -extern crate failure; -#[macro_use] extern crate failure_derive; pub mod error; pub mod element;