Skip to main content

knowledge_base_validation/
diagnostic.rs

1use std::fmt;
2use std::path::PathBuf;
3
4#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
5pub enum ValidationLayer {
6    Schema,
7    Ontology,
8    Domain,
9    Provenance,
10}
11
12impl fmt::Display for ValidationLayer {
13    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
14        let name = match self {
15            Self::Schema => "schema",
16            Self::Ontology => "ontology",
17            Self::Domain => "domain",
18            Self::Provenance => "provenance",
19        };
20        formatter.write_str(name)
21    }
22}
23
24#[derive(Clone, Debug, Eq, PartialEq)]
25pub struct Diagnostic {
26    pub layer: ValidationLayer,
27    pub path: PathBuf,
28    pub line: Option<usize>,
29    pub identifier: Option<String>,
30    pub message: String,
31}
32
33impl fmt::Display for Diagnostic {
34    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
35        write!(formatter, "{}", self.path.display())?;
36        if let Some(line) = self.line {
37            write!(formatter, ":{line}")?;
38        }
39        write!(formatter, " [{}]", self.layer)?;
40        if let Some(identifier) = &self.identifier {
41            write!(formatter, " [{identifier}]")?;
42        }
43        write!(formatter, " {}", self.message)
44    }
45}