Struct AnnotationList

Source
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>

Source

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.

Source

pub fn add(&mut self, annotation: Annotation) -> Result<&mut Self>

Add an Annotation to list. You may also use .info(), .warning() and .error() methods.

Source

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

Source

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

Source

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

Source

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.

Source

pub fn show_stdout(&self, stylesheet: &Stylesheet) -> Result<()>

Print error message to stdout. Output will be colorized if stdout is a TTY

Source

pub fn show_stderr(&self, stylesheet: &Stylesheet) -> Result<()>

Print error message to stderr. Output will be colorized if stderr is a TTY

Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

“Print” monochrome message to Vec<u8>

Source

pub fn to_ansi_bytes(&self, stylesheet: &Stylesheet) -> Result<Vec<u8>>

“Print” message to Vec<u8>, colorizing it using ANSI escape codes

Source

pub fn to_string(&self) -> Result<String>

“Print” monochrome message to String

§Panics

Panics if message cannot be converted to UTF-8

Source

pub fn to_ansi_string(&self, stylesheet: &Stylesheet) -> Result<String>

“Print” message to String, colorizing it using ANSI escape codes

§Panics

Panics if message cannot be converted to UTF-8

Trait Implementations§

Source§

impl<'a> Debug for AnnotationList<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for AnnotationList<'a>

Source§

fn eq(&self, other: &AnnotationList<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for AnnotationList<'a>

Source§

impl<'a> StructuralPartialEq for AnnotationList<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for AnnotationList<'a>

§

impl<'a> RefUnwindSafe for AnnotationList<'a>

§

impl<'a> Send for AnnotationList<'a>

§

impl<'a> Sync for AnnotationList<'a>

§

impl<'a> Unpin for AnnotationList<'a>

§

impl<'a> UnwindSafe for AnnotationList<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.