daedalus_planner/
diagnostics.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
11pub struct DiagnosticSpan {
12 pub pass: String,
13 pub node: Option<String>,
14 pub port: Option<String>,
15}
16
17#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
25#[non_exhaustive]
26pub enum DiagnosticCode {
27 NodeMissing,
28 PortMissing,
29 UnresolvedInput,
30 ConverterMissing,
31 TypeMismatch,
32 GpuUnsupported,
33 ScheduleConflict,
34 LintWarning,
35}
36
37#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
47pub struct Diagnostic {
48 pub code: DiagnosticCode,
49 pub message: String,
50 pub span: DiagnosticSpan,
51}
52
53impl Diagnostic {
54 pub fn new(code: DiagnosticCode, message: impl Into<String>) -> Self {
56 Self {
57 code,
58 message: message.into(),
59 span: DiagnosticSpan {
60 pass: String::new(),
61 node: None,
62 port: None,
63 },
64 }
65 }
66
67 pub fn in_pass(mut self, pass: &'static str) -> Self {
69 self.span.pass = pass.to_string();
70 self
71 }
72
73 pub fn at_node(mut self, node: impl Into<String>) -> Self {
75 self.span.node = Some(node.into());
76 self
77 }
78
79 pub fn at_port(mut self, port: impl Into<String>) -> Self {
81 self.span.port = Some(port.into());
82 self
83 }
84}