2016-04-15 02:51:50 +03:00
|
|
|
#[must_use]
|
2016-05-15 21:41:05 +12:00
|
|
|
#[derive(Debug, Clone)]
|
2016-04-15 02:51:50 +03:00
|
|
|
pub struct Summary {
|
|
|
|
// Encountered e.g. an IO error.
|
|
|
|
has_operational_errors: bool,
|
|
|
|
|
|
|
|
// Failed to reformat code because of parsing errors.
|
|
|
|
has_parsing_errors: bool,
|
|
|
|
|
|
|
|
// Code is valid, but it is impossible to format it properly.
|
|
|
|
has_formatting_errors: bool,
|
2016-06-20 20:42:29 +02:00
|
|
|
|
|
|
|
// Formatted code differs from existing code (write-mode diff only).
|
|
|
|
pub has_diff: bool,
|
2016-04-15 02:51:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Summary {
|
|
|
|
pub fn new() -> Summary {
|
|
|
|
Summary {
|
|
|
|
has_operational_errors: false,
|
|
|
|
has_parsing_errors: false,
|
|
|
|
has_formatting_errors: false,
|
2016-06-20 20:42:29 +02:00
|
|
|
has_diff: false,
|
2016-04-15 02:51:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_operational_errors(&self) -> bool {
|
|
|
|
self.has_operational_errors
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_parsing_errors(&self) -> bool {
|
|
|
|
self.has_parsing_errors
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_formatting_errors(&self) -> bool {
|
|
|
|
self.has_formatting_errors
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_operational_error(&mut self) {
|
|
|
|
self.has_operational_errors = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_parsing_error(&mut self) {
|
|
|
|
self.has_parsing_errors = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_formatting_error(&mut self) {
|
|
|
|
self.has_formatting_errors = true;
|
|
|
|
}
|
|
|
|
|
2016-06-20 20:42:29 +02:00
|
|
|
pub fn add_diff(&mut self) {
|
|
|
|
self.has_diff = true;
|
|
|
|
}
|
|
|
|
|
2016-04-15 02:51:50 +03:00
|
|
|
pub fn has_no_errors(&self) -> bool {
|
2016-06-20 20:42:29 +02:00
|
|
|
!(self.has_operational_errors || self.has_parsing_errors || self.has_formatting_errors ||
|
|
|
|
self.has_diff)
|
2016-04-15 02:51:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(&mut self, other: Summary) {
|
|
|
|
self.has_operational_errors |= other.has_operational_errors;
|
|
|
|
self.has_formatting_errors |= other.has_formatting_errors;
|
|
|
|
self.has_parsing_errors |= other.has_parsing_errors;
|
2016-06-20 20:42:29 +02:00
|
|
|
self.has_diff |= other.has_diff;
|
2016-04-15 02:51:50 +03:00
|
|
|
}
|
|
|
|
}
|