ergo_runtime/common/
error_info.rs1use std::borrow::Cow;
2
3pub trait ErrorInfo {
4 fn rule_id(&self) -> &'static str;
5 fn phase(&self) -> Phase;
6 fn doc_anchor(&self) -> &'static str;
7 fn summary(&self) -> Cow<'static, str>;
8 fn path(&self) -> Option<Cow<'static, str>>;
9 fn fix(&self) -> Option<Cow<'static, str>>;
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum Phase {
14 Registration,
15 Composition,
16 Execution,
17}
18
19#[derive(Debug, Clone, PartialEq)]
20pub struct RuleViolation {
21 pub rule_id: &'static str,
22 pub phase: Phase,
23 pub doc_anchor: &'static str,
24 pub summary: Cow<'static, str>,
25 pub path: Option<Cow<'static, str>>,
26 pub fix: Option<Cow<'static, str>>,
27}
28
29impl<E: ErrorInfo> From<E> for RuleViolation {
30 fn from(e: E) -> Self {
31 RuleViolation {
32 rule_id: e.rule_id(),
33 phase: e.phase(),
34 doc_anchor: e.doc_anchor(),
35 summary: e.summary(),
36 path: e.path(),
37 fix: e.fix(),
38 }
39 }
40}
41
42impl RuleViolation {
43 pub fn from_ref(e: &dyn ErrorInfo) -> Self {
44 RuleViolation {
45 rule_id: e.rule_id(),
46 phase: e.phase(),
47 doc_anchor: e.doc_anchor(),
48 summary: e.summary(),
49 path: e.path(),
50 fix: e.fix(),
51 }
52 }
53}