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 moreSource§impl Debug for Diagnostic
impl Debug for Diagnostic
Source§impl PartialEq for Diagnostic
impl PartialEq for Diagnostic
impl Eq for Diagnostic
impl StructuralPartialEq for Diagnostic
Auto Trait Implementations§
impl Freeze for Diagnostic
impl RefUnwindSafe for Diagnostic
impl Send for Diagnostic
impl Sync for Diagnostic
impl Unpin for Diagnostic
impl UnwindSafe for Diagnostic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.