use std::io;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("XML error: {0}")]
XmlError(#[from] rxml::Error),
#[error("I/O error: {0}")]
Io(io::Error),
#[error("the end of the document has been reached prematurely")]
EndOfDocument,
#[error("the prefix is invalid")]
InvalidPrefix,
#[error("the XML element is missing a namespace")]
MissingNamespace,
#[error("the prefix is already defined")]
DuplicatePrefix,
}
impl From<io::Error> for Error {
fn from(other: io::Error) -> Self {
match other.downcast::<rxml::Error>() {
Ok(e) => Self::XmlError(e),
Err(e) => Self::Io(e),
}
}
}
impl From<rxml::strings::Error> for Error {
fn from(err: rxml::strings::Error) -> Error {
rxml::error::Error::from(err).into()
}
}
pub type Result<T> = ::core::result::Result<T, Error>;