port error.rs to error_chain, bump version to 0.4.0
This commit is contained in:
parent
6323529cd7
commit
508c971416
4 changed files with 27 additions and 34 deletions
45
src/error.rs
45
src/error.rs
|
|
@ -7,33 +7,24 @@ use std::convert::From;
|
|||
use xml::writer::Error as WriterError;
|
||||
use xml::reader::Error as ReaderError;
|
||||
|
||||
/// An enum representing the possible errors.
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// An io::Error.
|
||||
IoError(io::Error),
|
||||
/// An error in the xml-rs `EventWriter`.
|
||||
XmlWriterError(WriterError),
|
||||
/// An error in the xml-rs `EventReader`.
|
||||
XmlReaderError(ReaderError),
|
||||
/// The end of the document has been reached unexpectedly.
|
||||
EndOfDocument,
|
||||
}
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
XmlWriterError(WriterError)
|
||||
/// An error with writing an XML event, from xml::writer::EventWriter.
|
||||
;
|
||||
XmlReaderError(ReaderError)
|
||||
/// An error with reading an XML event, from xml::reader::EventReader.
|
||||
;
|
||||
IoError(io::Error)
|
||||
/// An I/O error, from std::io.
|
||||
;
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(err: io::Error) -> Error {
|
||||
Error::IoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WriterError> for Error {
|
||||
fn from(err: WriterError) -> Error {
|
||||
Error::XmlWriterError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ReaderError> for Error {
|
||||
fn from(err: ReaderError) -> Error {
|
||||
Error::XmlReaderError(err)
|
||||
errors {
|
||||
/// En error which is returned when the end of the document was reached prematurely.
|
||||
EndOfDocument {
|
||||
description("the end of the document has been reached prematurely")
|
||||
display("the end of the document has been reached prematurely")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue