#[derive(Debug, Clone)]
pub struct ValidationResult {
pub is_valid: bool,
pub errors: Vec<String>,
pub warnings: Vec<String>,
pub staged_report: Option<crate::config::ConfigValidationReport>,
}
impl ValidationResult {
pub fn valid() -> Self {
Self {
is_valid: true,
errors: Vec::new(),
warnings: Vec::new(),
staged_report: None,
}
}
pub fn add_error(&mut self, error: String) {
self.errors.push(error);
self.is_valid = false;
}
pub fn add_warning(&mut self, warning: String) {
self.warnings.push(warning);
}
pub fn print_results(&self) {
for warning in &self.warnings {
eprintln!("Warning: {}", warning);
}
for error in &self.errors {
eprintln!("Error: {}", error);
}
}
}
impl Default for ValidationResult {
fn default() -> Self {
Self::valid()
}
}
#[derive(Debug)]
pub struct ValidationContext<'a> {
pub opt: &'a crate::config::OptimizerConfig,
pub result: &'a mut ValidationResult,
}
impl<'a> ValidationContext<'a> {
pub fn new(opt: &'a crate::config::OptimizerConfig, result: &'a mut ValidationResult) -> Self {
Self { opt, result }
}
pub fn add_error(&mut self, error: impl Into<String>) {
self.result.add_error(error.into());
}
pub fn add_warning(&mut self, warning: impl Into<String>) {
self.result.add_warning(warning.into());
}
}