Implement TempFileError and traits for it
This commit is contained in:
parent
900ffcb7d1
commit
808e44339a
1 changed files with 57 additions and 1 deletions
58
src/ui/external/editor.rs
vendored
58
src/ui/external/editor.rs
vendored
|
@ -4,6 +4,9 @@ use std::path::PathBuf;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use runtime::Runtime;
|
use runtime::Runtime;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -49,5 +52,58 @@ impl Drop for TempFile {
|
||||||
|
|
||||||
|
|
||||||
pub struct TempFileError {
|
pub struct TempFileError {
|
||||||
cause: Option<Box<Error>>,
|
desc: &'static str,
|
||||||
|
caused_by: Option<Box<Error>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TempFileError {
|
||||||
|
|
||||||
|
pub fn new(s: &'static str) -> TempFileError {
|
||||||
|
TempFileError {
|
||||||
|
desc: s,
|
||||||
|
caused_by: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_cause(s: &'static str, c: Box<Error>) -> 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue