rust_minifb/src/error.rs

48 lines
1.4 KiB
Rust
Raw Normal View History

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 {
/// Returned if menu Menu function isn't supported
2016-03-04 17:36:28 +01:00
MenusNotSupported,
/// Menu already exists
2016-03-04 17:36:28 +01:00
MenuExists(String),
/// Menu already exists
2016-03-04 17:36:28 +01:00
WindowCreate(String),
/// 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",
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,
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
}
}
}