Debian Codegraph @

src/error.rs

raw symbols SCIP
1 use std::io;
2 use std::fmt;
3 use std::error::Error as StdError;
4
5 use {OSError, Error, MountError};
6 use remount::RemountError;
7
8 impl OSError {
9 /// Convert error to the one providing extra useful information
10 pub fn explain(self) -> Error {
11 let text = self.1.explain();
12 match self.0 {
13 MountError::Io(e) => Error(self.1, e, text),
14 MountError::Remount(RemountError::Io(msg, io_err)) => {
15 Error(self.1, io_err, format!("{}, {}", msg, text))
16 },
17 MountError::Remount(err) => {
18 let text = format!("{}, {}", &err, text);
19 let err = Box::new(err);
20 Error(self.1,
21 io::Error::new(io::ErrorKind::InvalidData, err),
22 text)
23 },
24 }
25 }
26 }
27
28 impl fmt::Display for OSError {
29 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
30 write!(fmt, "{}: {}", self.1, self.0)
31 }
32 }
33
34 impl StdError for OSError {
35 fn cause(&self) -> Option<&StdError> {
36 Some(&self.0)
37 }
38 fn description(&self) -> &str {
39 self.0.description()
40 }
41 }
42
43 impl fmt::Display for Error {
44 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
45 write!(fmt, "{}: {} ({})", self.0, self.1, self.2)
46 }
47 }
48
49 impl StdError for Error {
50 fn cause(&self) -> Option<&StdError> {
51 Some(&self.1)
52 }
53 fn description(&self) -> &str {
54 self.1.description()
55 }
56 }