lib3mf_core/validation/
report.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4pub enum ValidationSeverity {
5 Error,
6 Warning,
7 Info,
8}
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct ValidationItem {
12 pub severity: ValidationSeverity,
13 pub code: u32, pub message: String,
15 pub suggestion: Option<String>,
16 pub context: Option<String>, }
18
19#[derive(Debug, Clone, Default, Serialize, Deserialize)]
20pub struct ValidationReport {
21 pub items: Vec<ValidationItem>,
22}
23
24impl ValidationReport {
25 pub fn new() -> Self {
26 Self::default()
27 }
28
29 pub fn add_error(&mut self, code: u32, msg: impl Into<String>) {
30 self.items.push(ValidationItem {
31 severity: ValidationSeverity::Error,
32 code,
33 message: msg.into(),
34 suggestion: None,
35 context: None,
36 });
37 }
38
39 pub fn add_warning(&mut self, code: u32, msg: impl Into<String>) {
40 self.items.push(ValidationItem {
41 severity: ValidationSeverity::Warning,
42 code,
43 message: msg.into(),
44 suggestion: None,
45 context: None,
46 });
47 }
48
49 pub fn add_info(&mut self, code: u32, msg: impl Into<String>) {
50 self.items.push(ValidationItem {
51 severity: ValidationSeverity::Info,
52 code,
53 message: msg.into(),
54 suggestion: None,
55 context: None,
56 });
57 }
58
59 pub fn has_errors(&self) -> bool {
60 self.items
61 .iter()
62 .any(|i| i.severity == ValidationSeverity::Error)
63 }
64}