]> git.lizzy.rs Git - rust.git/blob - src/summary.rs
Merge pull request #2138 from topecongiro/comments-around-trait-bounds
[rust.git] / src / summary.rs
1 #[must_use]
2 #[derive(Debug, Default, Clone)]
3 pub struct Summary {
4     // Encountered e.g. an IO error.
5     has_operational_errors: bool,
6
7     // Failed to reformat code because of parsing errors.
8     has_parsing_errors: bool,
9
10     // Code is valid, but it is impossible to format it properly.
11     has_formatting_errors: bool,
12
13     // Formatted code differs from existing code (write-mode diff only).
14     pub has_diff: bool,
15 }
16
17 impl Summary {
18     pub fn has_operational_errors(&self) -> bool {
19         self.has_operational_errors
20     }
21
22     pub fn has_parsing_errors(&self) -> bool {
23         self.has_parsing_errors
24     }
25
26     pub fn has_formatting_errors(&self) -> bool {
27         self.has_formatting_errors
28     }
29
30     pub fn add_operational_error(&mut self) {
31         self.has_operational_errors = true;
32     }
33
34     pub fn add_parsing_error(&mut self) {
35         self.has_parsing_errors = true;
36     }
37
38     pub fn add_formatting_error(&mut self) {
39         self.has_formatting_errors = true;
40     }
41
42     pub fn add_diff(&mut self) {
43         self.has_diff = 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             || self.has_diff)
49     }
50
51     pub fn add(&mut self, other: Summary) {
52         self.has_operational_errors |= other.has_operational_errors;
53         self.has_formatting_errors |= other.has_formatting_errors;
54         self.has_parsing_errors |= other.has_parsing_errors;
55         self.has_diff |= other.has_diff;
56     }
57
58     pub fn print_exit_codes() {
59         let exit_codes = r#"Exit Codes:
60     0 = No errors
61     1 = Encountered operational errors e.g. an IO error
62     2 = Failed to reformat code because of parsing errors
63     3 = Code is valid, but it is impossible to format it properly
64     4 = Formatted code differs from existing code (write-mode diff only)"#;
65         println!("{}", exit_codes);
66     }
67 }