pub struct AnnotationList<'a> { /* private fields */ }
Expand description
List of annotations applied to some input string. Doesn’t owns string, so has a limited lifetime.
Implementations§
Source§impl<'a> AnnotationList<'a>
impl<'a> AnnotationList<'a>
Sourcepub fn new(filename: impl AsRef<str>, string: &'a str) -> Self
pub fn new(filename: impl AsRef<str>, string: &'a str) -> Self
Create an annotation list from string. filename
is used only to format messages, so
corresponding file doesn’t need to exist.
Sourcepub fn add(&mut self, annotation: Annotation) -> Result<&mut Self>
pub fn add(&mut self, annotation: Annotation) -> Result<&mut Self>
Add an Annotation
to list. You may also use .info()
,
.warning()
and .error()
methods.
Sourcepub fn info(
&mut self,
range: Range<usize>,
header: impl AnnotationText,
text: impl AnnotationText,
) -> Result<&mut Self>
pub fn info( &mut self, range: Range<usize>, header: impl AnnotationText, text: impl AnnotationText, ) -> Result<&mut Self>
Add an Severity::Info
annotation to list. See Annotation::new
docs for details
Sourcepub fn warning(
&mut self,
range: Range<usize>,
header: impl AnnotationText,
text: impl AnnotationText,
) -> Result<&mut Self>
pub fn warning( &mut self, range: Range<usize>, header: impl AnnotationText, text: impl AnnotationText, ) -> Result<&mut Self>
Add an Severity::Warning
annotation to list. See Annotation::new
docs for details
Sourcepub fn error(
&mut self,
range: Range<usize>,
header: impl AnnotationText,
text: impl AnnotationText,
) -> Result<&mut Self>
pub fn error( &mut self, range: Range<usize>, header: impl AnnotationText, text: impl AnnotationText, ) -> Result<&mut Self>
Add an Severity::Error
annotation to list. See Annotation::new
docs for details
Sourcepub fn show<W: Write + WriteColor>(
&self,
stream: W,
stylesheet: &Stylesheet,
) -> Result<()>
pub fn show<W: Write + WriteColor>( &self, stream: W, stylesheet: &Stylesheet, ) -> Result<()>
Print an error message to stream using given stylesheet. If your stream implements
Write
, but not WriteColor
, consider wrapping
it into termcolor::Ansi
or termcolor::NoColor
.
This method uses no buffering, so you probably want to pass termcolor::Buffer
to it
rather than raw stream.
If you want to just print message to stdout/stderr, consider using
.print_stdout()
or
.print_stderr()
instead.
Sourcepub fn show_stdout(&self, stylesheet: &Stylesheet) -> Result<()>
pub fn show_stdout(&self, stylesheet: &Stylesheet) -> Result<()>
Print error message to stdout. Output will be colorized if stdout is a TTY
Sourcepub fn show_stderr(&self, stylesheet: &Stylesheet) -> Result<()>
pub fn show_stderr(&self, stylesheet: &Stylesheet) -> Result<()>
Print error message to stderr. Output will be colorized if stderr is a TTY
Sourcepub fn to_ansi_bytes(&self, stylesheet: &Stylesheet) -> Result<Vec<u8>>
pub fn to_ansi_bytes(&self, stylesheet: &Stylesheet) -> Result<Vec<u8>>
“Print” message to Vec<u8>
, colorizing it using ANSI escape codes