Struct source_span::fmt::Formatter

source ·
pub struct Formatter { /* private fields */ }
Expand description

Text formatter with span highlights.

This allows you to format a given input char stream with highlights and colors (if the colors feature is enabled). A Highlight is defined by a Span, a string label and a Style, and will be rendered with the stream:

1 | fn main() {
2 |     println!("Hello World!")
  |              ^^^^^^^^^^^^^^ highlighting this string
3 | }

Highlights spans can cover multiple lines and overlap. See the Highlight documentation for more informations.

Implementations§

source§

impl Formatter

source

pub fn new() -> Formatter

Create a new formatter with no highlights.

By default line numbers are showing. You can disable them using the hide_line_numbers method.

source

pub fn show_line_numbers(&mut self)

Show the line numbers in the output.

This is the default.

source

pub fn hide_line_numbers(&mut self)

Hide the line numbers in the output.

By default, line numbers are visible.

source

pub fn add(&mut self, span: Span, label: Option<String>, style: Style)

Add a span highlight.

source

pub fn get<I: Iterator<Item = Result<char>>>( &self, input: I, span: Span, ) -> Result<String>

Produce the formatted output.

Create a String containing the content of the input iterator given span, with the previously added highlights.

Auto Trait Implementations§

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

§

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

§

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.