lib3mf_core/validation/
report.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5pub enum ValidationSeverity {
6 Error,
8 Warning,
10 Info,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct ValidationItem {
17 pub severity: ValidationSeverity,
19 pub code: u32, pub message: String,
23 pub suggestion: Option<String>,
25 pub context: Option<String>, }
28
29#[derive(Debug, Clone, Default, Serialize, Deserialize)]
31pub struct ValidationReport {
32 pub items: Vec<ValidationItem>,
34}
35
36impl ValidationReport {
37 pub fn new() -> Self {
39 Self::default()
40 }
41
42 pub fn add_error(&mut self, code: u32, msg: impl Into<String>) {
44 self.items.push(ValidationItem {
45 severity: ValidationSeverity::Error,
46 code,
47 message: msg.into(),
48 suggestion: None,
49 context: None,
50 });
51 }
52
53 pub fn add_warning(&mut self, code: u32, msg: impl Into<String>) {
55 self.items.push(ValidationItem {
56 severity: ValidationSeverity::Warning,
57 code,
58 message: msg.into(),
59 suggestion: None,
60 context: None,
61 });
62 }
63
64 pub fn add_info(&mut self, code: u32, msg: impl Into<String>) {
66 self.items.push(ValidationItem {
67 severity: ValidationSeverity::Info,
68 code,
69 message: msg.into(),
70 suggestion: None,
71 context: None,
72 });
73 }
74
75 pub fn has_errors(&self) -> bool {
77 self.items
78 .iter()
79 .any(|i| i.severity == ValidationSeverity::Error)
80 }
81}