xmpp-rs/src/error.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

//! Provides an error type for this crate.
2017-02-19 19:46:44 +00:00
use std::convert::From;
/// Our main error type.
#[derive(Debug, Fail)]
pub enum Error {
/// An error from quick_xml.
#[fail(display = "XML error: {}", _0)]
XmlError(#[cause] ::quick_xml::errors::Error),
/// An UTF-8 conversion error.
#[fail(display = "UTF-8 error: {}", _0)]
Utf8Error(#[cause] ::std::str::Utf8Error),
/// An I/O error, from std::io.
#[fail(display = "IO error: {}", _0)]
IoError(#[cause] ::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,
}
impl From<::quick_xml::errors::Error> for Error {
fn from(err: ::quick_xml::errors::Error) -> Error {
Error::XmlError(err)
}
}
impl From<::std::str::Utf8Error> for Error {
fn from(err: ::std::str::Utf8Error) -> Error {
Error::Utf8Error(err)
2017-02-19 19:46:44 +00:00
}
}
2017-02-19 19:46:44 +00:00
impl From<::std::io::Error> for Error {
fn from(err: ::std::io::Error) -> Error {
Error::IoError(err)
2017-02-19 19:46:44 +00:00
}
}
/// Our simplified Result type.
pub type Result<T> = ::std::result::Result<T, Error>;