shacl_ast/compiled/
severity.rs1use iri_s::iri;
2use iri_s::IriS;
3use srdf::Iri as _;
4use srdf::Rdf;
5
6use crate::severity::Severity;
7use crate::*;
8
9use super::compiled_shacl_error::CompiledShaclError;
10use super::convert_iri_ref;
11
12#[derive(Hash, PartialEq, Eq, Debug)]
13pub enum CompiledSeverity<S: Rdf> {
14 Violation,
15 Warning,
16 Info,
17 Generic(S::IRI),
18}
19
20impl<S: Rdf> CompiledSeverity<S> {
21 pub fn compile(severity: Option<Severity>) -> Result<Option<Self>, CompiledShaclError> {
22 let ans = match severity {
23 Some(severity) => {
24 let severity = match severity {
25 Severity::Violation => CompiledSeverity::Violation,
26 Severity::Warning => CompiledSeverity::Warning,
27 Severity::Info => CompiledSeverity::Info,
28 Severity::Generic(iri_ref) => {
29 CompiledSeverity::Generic(convert_iri_ref::<S>(iri_ref)?)
30 }
31 };
32 Some(severity)
33 }
34 None => None,
35 };
36
37 Ok(ans)
38 }
39}
40
41impl<S: Rdf> From<&CompiledSeverity<S>> for IriS {
42 fn from(value: &CompiledSeverity<S>) -> Self {
43 match value {
44 CompiledSeverity::Violation => iri!(SH_VIOLATION_STR),
45 CompiledSeverity::Warning => iri!(SH_WARNING_STR),
46 CompiledSeverity::Info => iri!(SH_INFO_STR),
47 CompiledSeverity::Generic(iri) => {
48 let iri_string = iri.as_str();
49 iri!(iri_string)
50 }
51 }
52 }
53}