mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-24 03:41:29 +11:00
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
|
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
|
||
|
MenusNotSupported,
|
||
|
/// Menu already exists
|
||
|
MenuExists(String),
|
||
|
/// Menu already exists
|
||
|
WindowCreate(String),
|
||
|
}
|
||
|
|
||
|
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",
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn cause(&self) -> Option<&StdError> {
|
||
|
match *self {
|
||
|
Error::MenusNotSupported => None,
|
||
|
Error::MenuExists(_) => None,
|
||
|
Error::WindowCreate(_) => None,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl fmt::Display for Error {
|
||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||
|
match *self {
|
||
|
Error::MenusNotSupported => {
|
||
|
write!(fmt, "{}", self.description())
|
||
|
},
|
||
|
Error::MenuExists(ref e) => {
|
||
|
write!(fmt, "{} {:?}", self.description(), e)
|
||
|
},
|
||
|
Error::WindowCreate(ref e) => {
|
||
|
write!(fmt, "{} {:?}", self.description(), e)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|