pub struct EmitterWriter<'a> { /* private fields */ }Expand description
EmitterWriter implements trait Emitter based on termcolor1.0
for rendering diagnostic as strings and displaying them to the terminal.
termcolor1.0 supports displaying colorful string to terminal.
§Examples
// 1. Create a EmitterWriter
let mut term_emitter = EmitterWriter::default();
// 2. Create a diagnostic for emitting.
let mut diagnostic = Diagnostic::<DiagnosticStyle>::new();
// 3. Create components wrapped by `Box<>`.
let err_label = Box::new(Label::Error("E3033".to_string()));
let msg = Box::new(": this is an error!".to_string());
// 4. Add components to `Diagnostic`.
diagnostic.append_component(err_label);
diagnostic.append_component(msg);
// 5. Emit the diagnostic.
term_emitter.emit_diagnostic(&diagnostic);Implementations§
Source§impl<'a> EmitterWriter<'a>
impl<'a> EmitterWriter<'a>
Sourcepub fn new_with_writer(dst: Destination<'a>) -> Self
pub fn new_with_writer(dst: Destination<'a>) -> Self
Return a Destination with custom writer.
§Examples
use compiler_base_error::Destination;
use compiler_base_error::EmitterWriter;
use termcolor::ColorChoice;
// 1. Create a `Destination` and close the color.
let dest = Destination::from_stderr(ColorChoice::Never);
// 2. Create the EmiterWriter by `Destination` with writer stderr.
let emitter_writer = EmitterWriter::new_with_writer(dest);Trait Implementations§
Source§impl<'a> Default for EmitterWriter<'a>
impl<'a> Default for EmitterWriter<'a>
Source§fn default() -> Self
fn default() -> Self
Return a Destination with writer stderr.
Source§impl<'a, T> Emitter<T> for EmitterWriter<'a>
impl<'a, T> Emitter<T> for EmitterWriter<'a>
Source§fn supports_color(&self) -> bool
fn supports_color(&self) -> bool
Checks if we can use colors in the current output stream.
Depends on termcolor1.0 which supports color.
Source§fn emit_diagnostic(&mut self, diag: &Diagnostic<T>) -> Result<()>
fn emit_diagnostic(&mut self, diag: &Diagnostic<T>) -> Result<()>
Emit a structured diagnostic.
It will call format_diagnostic first to format the Diagnostic into StyledString.
It will panic if something wrong during emitting.
Source§fn format_diagnostic(
&mut self,
diag: &Diagnostic<T>,
) -> Result<StyledBuffer<T>, ComponentError>
fn format_diagnostic( &mut self, diag: &Diagnostic<T>, ) -> Result<StyledBuffer<T>, ComponentError>
Format struct Diagnostic into String and render String into StyledString,
and save StyledString in StyledBuffer.
Auto Trait Implementations§
impl<'a> !Freeze for EmitterWriter<'a>
impl<'a> !RefUnwindSafe for EmitterWriter<'a>
impl<'a> Send for EmitterWriter<'a>
impl<'a> !Sync for EmitterWriter<'a>
impl<'a> Unpin for EmitterWriter<'a>
impl<'a> !UnwindSafe for EmitterWriter<'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
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