Struct Highlight

Source
pub struct Highlight { /* private fields */ }
Expand description

Text highlight.

Defines what should be highlighted in the text formatted with the Formatter. A highlight is composed of a span a label and a style. The formatter will underline the text in the given span and draw the label’s text on its side, with the given style.

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

§Highlight spanning multiple lines

The highlight span can cover multiple lines. In that case, only the first and last elements will be decorated using the style’s marker charatcer (^ in the below example).

1 |   fn main() {
  |  ___________^
2 | |     println!("Hello World!")
3 | | }
  | |_^ this span covers more than one line

§Entangled highlights

Different highlights can overlap without breaking the formatted output, but it may become difficult to read the exact boundary of each highlight.

1 |   fn main() {
  |          __ ^
  |  _________|_|
  | |         |
  | |         this is a pair of parenthesis
2 | |     println!("Hello World!")
  | |             ^^^^^^^^^^^^^^^^ this is a pair of parenthesis
  | |             |_____________||
  | |                           |
  | |                           this is a string. Hard to see where it starts, uh?
3 | | }
  | |_^ this is a pair of braces

Here the underline character for the string is the same as the boundary marker for the parenthesis, making it hard to see which is which. One possible workaround is to change the Style of the highlights. Changing the boundary marker for the parenthesis to | makes it easier to read the formatted output:

1 |   fn main() {
  |          __ ^
  |  _________|_|
  | |         |
  | |         this is a pair of parenthesis
2 | |     println!("Hello World!")
  | |             |^^^^^^^^^^^^^^| this is a pair of parenthesis
  | |             |_____________||
  | |                           |
  | |                           this is a string. Hard to see where it starts, uh?
3 | | }
  | |_^ this is a pair of braces

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

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.