macho_core/model/validate/
diagnostics.rs1use crate::model::addr::ThinFileOffset;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4#[non_exhaustive]
6pub enum Severity {
7 Error,
9 Warning,
11 Info,
13}
14
15#[derive(Debug, Clone)]
16pub struct DiagnosticCode(pub &'static str);
18
19#[derive(Debug, Clone)]
20pub struct Span {
22 pub offset: ThinFileOffset,
24 pub size: u64,
26 pub label: Option<String>,
28}
29
30#[derive(Debug, Clone)]
31pub struct Diagnostic {
33 pub severity: Severity,
35 pub code: DiagnosticCode,
37 pub message: String,
39 pub spans: Vec<Span>,
41}
42
43impl Diagnostic {
44 pub fn error(code: &'static str, message: impl Into<String>) -> Self {
46 Self {
47 severity: Severity::Error,
48 code: DiagnosticCode(code),
49 message: message.into(),
50 spans: Vec::new(),
51 }
52 }
53
54 pub fn warning(code: &'static str, message: impl Into<String>) -> Self {
56 Self {
57 severity: Severity::Warning,
58 code: DiagnosticCode(code),
59 message: message.into(),
60 spans: Vec::new(),
61 }
62 }
63
64 pub fn info(code: &'static str, message: impl Into<String>) -> Self {
66 Self {
67 severity: Severity::Info,
68 code: DiagnosticCode(code),
69 message: message.into(),
70 spans: Vec::new(),
71 }
72 }
73
74 pub fn with_span(mut self, span: Span) -> Self {
76 self.spans.push(span);
77 self
78 }
79}