diff --git a/src/error.rs b/src/error.rs index fc96a08..579cee4 100644 --- a/src/error.rs +++ b/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 {