diff --git a/src/ui/external/editor.rs b/src/ui/external/editor.rs index 4442d0a1..f8b26252 100644 --- a/src/ui/external/editor.rs +++ b/src/ui/external/editor.rs @@ -4,6 +4,9 @@ use std::path::PathBuf; use std::fs::File; use std::error::Error; +use std::fmt::{Debug, Display, Formatter}; +use std::fmt; + use runtime::Runtime; /* @@ -49,5 +52,58 @@ impl Drop for TempFile { pub struct TempFileError { - cause: Option>, + desc: &'static str, + caused_by: Option>, } + +impl TempFileError { + + pub fn new(s: &'static str) -> TempFileError { + TempFileError { + desc: s, + caused_by: None, + } + } + + pub fn with_cause(s: &'static str, c: Box) -> TempFileError { + TempFileError { + desc: s, + caused_by: Some(c), + } + } + +} + +impl Display for TempFileError { + + fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + write!(fmt, "TempFileError: '{}'", self.desc); + Ok(()) + } +} + +impl Debug for TempFileError { + + fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + write!(fmt, "TempFileError: '{}'", self.desc); + + if let Some(ref e) = self.caused_by { + write!(fmt, " cause: {:?}\n\n", e); + } + + Ok(()) + } +} + +impl Error for TempFileError { + + fn description(&self) -> &str { + self.desc + } + + fn cause(&self) -> Option<&Error> { + self.caused_by.as_ref().map(|e| &**e) + } + +} +