diff --git a/src/sdl2/messagebox.rs b/src/sdl2/messagebox.rs index cb53bc5d..2fd5a75c 100644 --- a/src/sdl2/messagebox.rs +++ b/src/sdl2/messagebox.rs @@ -1,4 +1,5 @@ use std::ffi::{CString, NulError}; +use std::fmt; use std::ptr; use std::os::raw::{c_char,c_int}; @@ -81,6 +82,20 @@ pub enum ShowMessageError { SdlError(String), } +impl fmt::Display for ShowMessageError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use self::ShowMessageError::*; + + match *self { + InvalidTitle(ref e) => write!(f, "Invalid title: {}", e), + InvalidMessage(ref e) => write!(f, "Invalid message: {}", e), + InvalidButton(ref e, value) => write!(f, + "Invalid button ({}): {}", value, e), + SdlError(ref e) => write!(f, "SDL error: {}", e) + } + } +} + /// Show a simple message box, meant to be informative only. /// /// There is no way to know if the user clicked "Ok" or closed the message box,