switchyard_translation/
diagnostic.rs1use serde::{Deserialize, Serialize};
7
8use crate::format::FormatId;
9
10#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
12pub enum DiagnosticSeverity {
13 Info,
14 Warning,
15 Error,
16}
17
18#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
20pub struct TranslationDiagnostic {
21 pub severity: DiagnosticSeverity,
22 pub code: String,
23 pub message: String,
24 pub source: Option<FormatId>,
25 pub target: Option<FormatId>,
26 pub path: Option<String>,
27}
28
29impl TranslationDiagnostic {
30 pub fn warning(code: impl Into<String>, message: impl Into<String>) -> Self {
32 Self {
33 severity: DiagnosticSeverity::Warning,
34 code: code.into(),
35 message: message.into(),
36 source: None,
37 target: None,
38 path: None,
39 }
40 }
41
42 pub fn at_path(mut self, path: impl Into<String>) -> Self {
44 self.path = Some(path.into());
45 self
46 }
47
48 pub fn with_formats(
50 mut self,
51 source: impl Into<FormatId>,
52 target: impl Into<FormatId>,
53 ) -> Self {
54 self.source = Some(source.into());
55 self.target = Some(target.into());
56 self
57 }
58}