Implement std::error::Error for Error.
This was removed in 0.11.1 with the removal of failure, but is used by people so let’s reintroduce it. The cause of an XmlError is pending on this PR from quick-xml: https://github.com/tafia/quick-xml/pull/170 Fixes #15. Fixes #18.
This commit is contained in:
parent
0db94e554d
commit
11a5c49470
1 changed files with 18 additions and 0 deletions
18
src/error.rs
18
src/error.rs
|
@ -1,6 +1,7 @@
|
|||
//! Provides an error type for this crate.
|
||||
|
||||
use std::convert::From;
|
||||
use std::error::Error as StdError;
|
||||
|
||||
/// Our main error type.
|
||||
#[derive(Debug)]
|
||||
|
@ -28,6 +29,23 @@ pub enum Error {
|
|||
CommentsDisabled,
|
||||
}
|
||||
|
||||
impl StdError for Error {
|
||||
fn cause(&self) -> Option<&dyn StdError> {
|
||||
match self {
|
||||
// TODO: return Some(e) for this case after the merge of
|
||||
// https://github.com/tafia/quick-xml/pull/170
|
||||
Error::XmlError(_e) => None,
|
||||
Error::Utf8Error(e) => Some(e),
|
||||
Error::IoError(e) => Some(e),
|
||||
Error::EndOfDocument => None,
|
||||
Error::InvalidElementClosed => None,
|
||||
Error::InvalidElement => None,
|
||||
#[cfg(not(comments))]
|
||||
Error::CommentsDisabled => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
|
|
Loading…
Reference in a new issue