[−][src]Struct source_span::fmt::Formatter
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]
&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.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Formatter
impl Send for Formatter
impl Sync for Formatter
impl Unpin for Formatter
impl UnwindSafe for Formatter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,