2016-03-04 17:36:28 +01:00
|
|
|
use std::error::Error as StdError;
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
/// Errors that can be return from various operatiors
|
|
|
|
///
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2017-08-11 12:41:24 +02:00
|
|
|
/// Returned if menu Menu function isn't supported
|
2016-03-04 17:36:28 +01:00
|
|
|
MenusNotSupported,
|
2017-08-11 12:41:24 +02:00
|
|
|
/// Menu already exists
|
2016-03-04 17:36:28 +01:00
|
|
|
MenuExists(String),
|
2017-08-11 12:41:24 +02:00
|
|
|
/// Menu already exists
|
2016-03-04 17:36:28 +01:00
|
|
|
WindowCreate(String),
|
2017-08-11 12:41:24 +02:00
|
|
|
/// Unable to Update
|
|
|
|
UpdateFailed(String),
|
2016-03-04 17:36:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl StdError for Error {
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
Error::MenusNotSupported => "Menus not supported",
|
|
|
|
Error::MenuExists(_) => "Menu already exists",
|
2017-08-11 12:41:24 +02:00
|
|
|
Error::WindowCreate(_) => "Failed to create window",
|
|
|
|
Error::UpdateFailed(_) => "Failed to Update",
|
2016-03-04 17:36:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-21 10:37:47 +02:00
|
|
|
fn cause(&self) -> Option<&dyn StdError> {
|
2016-03-04 17:36:28 +01:00
|
|
|
match *self {
|
|
|
|
Error::MenusNotSupported => None,
|
|
|
|
Error::MenuExists(_) => None,
|
|
|
|
Error::WindowCreate(_) => None,
|
2017-08-11 12:41:24 +02:00
|
|
|
Error::UpdateFailed(_) => None,
|
2016-03-04 17:36:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2019-11-27 08:03:33 +01:00
|
|
|
Error::MenusNotSupported => write!(fmt, "{}", self.description()),
|
|
|
|
Error::MenuExists(ref e) => write!(fmt, "{} {:?}", self.description(), e),
|
|
|
|
Error::WindowCreate(ref e) => write!(fmt, "{} {:?}", self.description(), e),
|
|
|
|
Error::UpdateFailed(ref e) => write!(fmt, "{} {:?}", self.description(), e),
|
2016-03-04 17:36:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|