pub struct Diagnostic<T>{ /* private fields */ }Expand description
Diagnostic is a collection of various components,
and any data structure that implements Component can be a part of Diagnostic.
§Examples
// If you want a diagnostic message “error[E3033]: this is an error!”.
let mut diagnostic = Diagnostic::new();
// First, create a label component wrapped by `Box<>`
let err_label = Box::new(Label::Error("E3033".to_string()));
// Second, add the label component to `Diagnostic`.
diagnostic.append_component(err_label);
// Then, create a string component wrapped by `Box<>`.
let msg = Box::new(": this is an error!".to_string());
// And add it to `Diagnostic`.
diagnostic.append_component(msg);
// Create a `Styledbuffer` to get the result.
let mut sb = StyledBuffer::<DiagnosticStyle>::new();
// Create an error set for collecting errors.
let mut errs = vec![];
// Rendering !
diagnostic.format(&mut sb, &mut errs);
let result = sb.render();
// “error[E3033]: this is an error!” is only one line.
assert_eq!(result.len(), 1);
// “error[E3033]: this is an error!” has three different style snippets.
// "error" - DiagnosticStyle::NeedFix
// "[E3033]" - DiagnosticStyle::Helpful
// ": this is an error!" - None
// `DiagnosticStyle` can be rendered into different text colors and formats when diaplaying.
assert_eq!(result.get(0).unwrap().len(), 3);
assert_eq!(result.get(0).unwrap().get(0).unwrap().text, "error");
assert_eq!(result.get(0).unwrap().get(1).unwrap().text, "[E3033]");
assert_eq!(result.get(0).unwrap().get(2).unwrap().text, ": this is an error!");
assert_eq!(result.get(0).unwrap().get(0).unwrap().style, Some(DiagnosticStyle::NeedFix));
assert_eq!(result.get(0).unwrap().get(1).unwrap().style, Some(DiagnosticStyle::Helpful));
assert_eq!(result.get(0).unwrap().get(2).unwrap().style, None);Implementations§
Trait Implementations§
Source§impl<T> Component<T> for Diagnostic<T>
impl<T> Component<T> for Diagnostic<T>
Source§fn format(&self, sb: &mut StyledBuffer<T>, errs: &mut Vec<ComponentFormatError>)
fn format(&self, sb: &mut StyledBuffer<T>, errs: &mut Vec<ComponentFormatError>)
Source§impl<T> Debug for Diagnostic<T>
impl<T> Debug for Diagnostic<T>
Source§impl<T> Default for Diagnostic<T>
impl<T> Default for Diagnostic<T>
Source§fn default() -> Diagnostic<T>
fn default() -> Diagnostic<T>
Returns the “default value” for a type. Read more
Source§impl<T> PartialEq for Diagnostic<T>
impl<T> PartialEq for Diagnostic<T>
Auto Trait Implementations§
impl<T> Freeze for Diagnostic<T>
impl<T> !RefUnwindSafe for Diagnostic<T>
impl<T> !Send for Diagnostic<T>
impl<T> !Sync for Diagnostic<T>
impl<T> Unpin for Diagnostic<T>
impl<T> !UnwindSafe for Diagnostic<T>
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more