Struct source_span::fmt::Highlight
source · pub struct Highlight { /* private fields */ }Expand description
Span highlight.
Used to define what should be highlighted in the text formatted with the Formatter.
Given a span a label and a style, the formatter will add an line under the elements of the
highlight span, along with the label (if any).
1 | fn main() {
2 | println!("Hello World!")
| ^^^^^^^^^^^^^^ highlighting this string
3 | }
§Multiline spans
The highlight span can cover multiple lines. In that case, only the first and last elements will be underlined (or pointed).
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