]> git.lizzy.rs Git - rust.git/blob - src/summary.rs
Merge pull request #923 from matklad/proper-exit-code
[rust.git] / src / summary.rs
1 #[must_use]
2 pub struct Summary {
3     // Encountered e.g. an IO error.
4     has_operational_errors: bool,
5
6     // Failed to reformat code because of parsing errors.
7     has_parsing_errors: bool,
8
9     // Code is valid, but it is impossible to format it properly.
10     has_formatting_errors: bool,
11 }
12
13 impl Summary {
14     pub fn new() -> Summary {
15         Summary {
16             has_operational_errors: false,
17             has_parsing_errors: false,
18             has_formatting_errors: false,
19         }
20     }
21
22     pub fn has_operational_errors(&self) -> bool {
23         self.has_operational_errors
24     }
25
26     pub fn has_parsing_errors(&self) -> bool {
27         self.has_parsing_errors
28     }
29
30     pub fn has_formatting_errors(&self) -> bool {
31         self.has_formatting_errors
32     }
33
34     pub fn add_operational_error(&mut self) {
35         self.has_operational_errors = true;
36     }
37
38     pub fn add_parsing_error(&mut self) {
39         self.has_parsing_errors = true;
40     }
41
42     pub fn add_formatting_error(&mut self) {
43         self.has_formatting_errors = true;
44     }
45
46     pub fn has_no_errors(&self) -> bool {
47         !(self.has_operational_errors || self.has_parsing_errors || self.has_formatting_errors)
48     }
49
50     pub fn add(&mut self, other: Summary) {
51         self.has_operational_errors |= other.has_operational_errors;
52         self.has_formatting_errors |= other.has_formatting_errors;
53         self.has_parsing_errors |= other.has_parsing_errors;
54     }
55 }