Skip to main content

shacl_ast/ast/
severity.rs

1use iri_s::IriS;
2use prefixmap::{IriRef, IriRefError};
3use rudof_rdf::rdf_core::vocabs::ShaclVocab;
4use std::fmt::Display;
5
6#[derive(Debug, Clone, PartialEq)]
7pub enum Severity {
8    Trace,
9    Debug,
10    Info,
11    Warning,
12    Violation,
13    Generic(IriRef),
14}
15
16impl TryFrom<Severity> for IriS {
17    type Error = IriRefError;
18
19    fn try_from(value: Severity) -> Result<Self, Self::Error> {
20        match value {
21            Severity::Trace => Ok(ShaclVocab::sh_trace().clone()),
22            Severity::Debug => Ok(ShaclVocab::sh_debug().clone()),
23            Severity::Info => Ok(ShaclVocab::sh_info().clone()),
24            Severity::Warning => Ok(ShaclVocab::sh_warning().clone()),
25            Severity::Violation => Ok(ShaclVocab::sh_violation().clone()),
26            Severity::Generic(iri_ref) => iri_ref.get_iri().cloned(),
27        }
28    }
29}
30
31impl Display for Severity {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        match self {
34            Severity::Trace => write!(f, "Trace"),
35            Severity::Debug => write!(f, "Debug"),
36            Severity::Violation => write!(f, "Violation"),
37            Severity::Warning => write!(f, "Warning"),
38            Severity::Info => write!(f, "Info"),
39            Severity::Generic(iri_ref) => write!(f, "Severity({iri_ref})"),
40        }
41    }
42}