1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use std::borrow::Cow;
use std::error::Error;
use std::fmt;
use std::io;
#[derive(Debug)]
pub struct ParseError {
desc: String,
}
impl ParseError {
pub fn new(detail: String) -> ParseError {
ParseError {
desc: format!("Mount parsing: {}", detail),
}
}
}
impl Error for ParseError {
fn description(&self) -> &str {
self.desc.as_ref()
}
}
impl From<io::Error> for ParseError {
fn from(err: io::Error) -> ParseError {
ParseError::new(format!("Failed to read the mounts file: {}", err))
}
}
impl fmt::Display for ParseError {
fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
write!(out, "{}", self.description())
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum LineError {
MissingSpec,
MissingFile,
InvalidFilePath(String),
InvalidFile(String),
MissingVfstype,
MissingMntops,
MissingFreq,
InvalidFreq(String),
MissingPassno,
InvalidPassno(String),
}
impl fmt::Display for LineError {
fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
let desc: Cow<_> = match *self {
LineError::MissingSpec => "Missing field #1 (spec)".into(),
LineError::MissingFile => "Missing field #2 (file)".into(),
LineError::InvalidFilePath(ref f) => format!("Bad field #2 (file) value (not absolute path): {}", f).into(),
LineError::InvalidFile(ref f) => format!("Bad field #2 (file) value: {}", f).into(),
LineError::MissingVfstype => "Missing field #3 (vfstype)".into(),
LineError::MissingMntops => "Missing field #4 (mntops)".into(),
LineError::MissingFreq => "Missing field #5 (freq)".into(),
LineError::InvalidFreq(ref f) => format!("Bad field #5 (dump) value: {}", f).into(),
LineError::MissingPassno => "Missing field #6 (passno)".into(),
LineError::InvalidPassno(ref f) => format!("Bad field #6 (passno) value: {}", f).into(),
};
write!(out, "Line parsing: {}", desc)
}
}