1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
use std::error::Error; use std; use std::fmt; use std::string; use serde_xml_rs; use xml; #[derive(Debug)] pub enum UrdfError { File(::std::io::Error), Xml(::serde_xml_rs::Error), RustyXml(::xml::BuilderError), Parse(String), Command(String), } pub type Result<T> = ::std::result::Result<T, UrdfError>; impl fmt::Display for UrdfError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { UrdfError::File(ref err) => err.fmt(f), UrdfError::Xml(ref err) => err.fmt(f), UrdfError::RustyXml(ref err) => err.fmt(f), UrdfError::Parse(ref msg) => write!(f, "parse error {}", msg), UrdfError::Command(ref msg) => write!(f, "command error {}", msg), } } } impl Error for UrdfError { fn description(&self) -> &str { match *self { UrdfError::File(ref err) => err.description(), UrdfError::Xml(ref err) => err.description(), UrdfError::RustyXml(ref err) => err.description(), UrdfError::Parse(ref err) => &err, UrdfError::Command(ref err) => &err, } } } impl From<std::io::Error> for UrdfError { fn from(err: std::io::Error) -> UrdfError { UrdfError::File(err) } } impl From<serde_xml_rs::Error> for UrdfError { fn from(err: serde_xml_rs::Error) -> UrdfError { UrdfError::Xml(err) } } impl From<xml::BuilderError> for UrdfError { fn from(err: xml::BuilderError) -> UrdfError { UrdfError::RustyXml(err) } } impl<'a> From<&'a str> for UrdfError { fn from(err: &'a str) -> UrdfError { UrdfError::Command(err.to_owned()) } } impl From<string::FromUtf8Error> for UrdfError { fn from(err: string::FromUtf8Error) -> UrdfError { UrdfError::Command(err.description().to_owned()) } }