pub struct Diagnostic {
pub title: String,
pub text: Option<String>,
pub level: Level,
pub location: Option<TextSpan>,
pub hint: Option<String>,
pub content: Option<String>,
}Expand description
Represents a diagnostic message, which includes information about an error or warning and can be pretty-printed to the console.
Fields§
§title: StringThe title or summary of the diagnostic message.
text: Option<String>An optional detailed description of the diagnostic message.
level: LevelThe severity level of the diagnostic message (e.g., Error, Warning).
location: Option<TextSpan>The location in the source code where the error or warning occurred, represented as a TextSpan.
hint: Option<String>An optional hint that provides additional guidance on resolving the issue.
content: Option<String>The content of the source code related to the diagnostic.
Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn log_pretty(&self, buff: &mut BufWriter<Stderr>)
pub fn log_pretty(&self, buff: &mut BufWriter<Stderr>)
Logs the diagnostic in a human-readable format to the provided buffer.
The message is colored according to its severity level, and the source code around the error location (if available) is highlighted.
§Arguments
buff- A mutable reference to aBufWriterthat writes tostderr.
§Example
use std::io::BufWriter;
use log::Level;
use roan_error::{Diagnostic, Position, TextSpan};
let diagnostic = Diagnostic {
title: "Syntax Error".to_string(),
text: None,
level: Level::Error,
location: Some(TextSpan::new(Position::new(1, 1, 0), Position::new(1, 5, 4), "test".to_string())),
hint: None,
content: Some("let x = ;".to_string()),
};
let mut buff = BufWriter::new(std::io::stderr());
diagnostic.log_pretty(&mut buff);Sourcepub fn print_hint(&self, buff: &mut BufWriter<Stderr>)
pub fn print_hint(&self, buff: &mut BufWriter<Stderr>)
Prints a hint message (if available) to the provided buffer.
§Arguments
buff- A mutable reference to aBufWriterthat writes tostderr.
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more