pub struct Diagnostic {
pub headline: String,
pub path: String,
pub line: u32,
pub col: u32,
pub source_line: String,
pub message: String,
pub hint: Option<String>,
}Expand description
A single compile error. The front end stops at the first one (docs/ERRORS.md:
“one issue at a time”), so a failed compile yields exactly one Diagnostic.
Fields§
§headline: StringThe meme framing line, e.g. very error. much confuse.. A more specific
headline is used when one fits (very tab. much confuse.).
path: StringPath of the source file, shown above the offending line.
line: u321-based line the error points at.
col: u321-based column the caret sits under.
source_line: StringThe offending source line, verbatim (no trailing newline).
message: StringThe precise, plain-language explanation printed after the caret.
hint: Option<String>An optional concrete fix, rendered as such fix: ….
Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn new(
path: impl Into<String>,
line: u32,
col: u32,
source_line: impl Into<String>,
message: impl Into<String>,
) -> Diagnostic
pub fn new( path: impl Into<String>, line: u32, col: u32, source_line: impl Into<String>, message: impl Into<String>, ) -> Diagnostic
Build a diagnostic with the default headline.
Sourcepub fn with_headline(self, headline: impl Into<String>) -> Diagnostic
pub fn with_headline(self, headline: impl Into<String>) -> Diagnostic
Replace the default headline with a specific meme framing.
Sourcepub fn with_hint(self, hint: impl Into<String>) -> Diagnostic
pub fn with_hint(self, hint: impl Into<String>) -> Diagnostic
Attach a such fix: … hint.
Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Render the diagnostic in the exact docs/ERRORS.md shape:
very error. much confuse.
examples/hello.doge:4
bark "hello" + 5
^ cannot + a Str and an Int
such fix: turn the Int into a Str first, e.g. str(5)The code line is indented four spaces; the caret sits under col
(1-based), so its leading padding is 4 + (col - 1) spaces.
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more