pub struct Formatted<'a> { /* private fields */ }Expand description
A diagnostic formatted for printing.
A Formatted can be printing and converted to a string directly via it’s
Display implementation.
Alternatively, you can iterate over the individual Lines and from there over pairs of
&str and Style. This allows you to apply custom styling (e.g. colors) to individual parts
of the diagnostic.
Formatted also provides a short one-line summary.
§Example
use aldrin_parser::{Diagnostic, Parser};
let parsed = Parser::new().parse("schemas/duplicate_id.aldrin");
let err = &parsed.errors()[0];
let formatted = err.format(&parsed);
// Print via Display:
eprintln!("{}", formatted);
// Print a one-line summary:
eprintln!("Error: {}.", formatted.summary());
// Print manually to apply styling to the output:
for line in &formatted {
for (chunk, style) in line {
// Apply style to chunk, e.g. colorize the output.
eprint!("{}", chunk);
}
eprintln!();
}Implementations§
Source§impl<'a> Formatted<'a>
impl<'a> Formatted<'a>
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Formatted<'a>
impl<'a> RefUnwindSafe for Formatted<'a>
impl<'a> Send for Formatted<'a>
impl<'a> Sync for Formatted<'a>
impl<'a> Unpin for Formatted<'a>
impl<'a> UnwindSafe for Formatted<'a>
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