[][src]Struct source_span::fmt::Formatter

pub struct Formatter { /* fields omitted */ }

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.

Methods

impl Formatter[src]

#[must_use] pub fn new() -> Self[src]

Create a new formatter with no highlights.

Note

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

#[must_use] pub const fn with_color(margin_color: Color) -> Self[src]

Create a new formatter with no highlights and the specified margin color.

Note

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

pub fn show_line_numbers(&mut self)[src]

Show the line numbers in the output.

This is the default.

pub fn hide_line_numbers(&mut self)[src]

Hide the line numbers in the output.

By default, line numbers are visible.

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

Add a span highlight.

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

Produce the formatted output.

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

Trait Implementations

impl Default for Formatter[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.