Module source_span::fmt

source ·
Expand description

Source code formatter with span highlights and notes.

Here are the kind of things you can produce with the Formatter:

01 |     pub fn fibonacci(n: i32) -> u64 {
   |                     ________        ^
   |  __________________________|________|
   | |                          |
   | |                          this is a pair of parenthesis
02 | |           if n < 0 {
   | |  __________________^
03 | | |                 panic!("{} is negative!", n);
   | | |                       ^"^^             "   ^ this is a pair of parenthesis
   | | |                       ||_|_____________|   |
   | | |                       |__|_____________|___|
   | | |                          |             |
   | | |                          this is a pair of braces
   | | |                                        |
   | | |                                        this is a string
04 | | |         } else if n == 0 {
   | | |_________^                ^
   | |  _________|________________|
   | | |         |
   | | |         this is a pair of braces
05 | | |                 panic!("zero is not a right argument to fibonacci()!");
   | | |                       ^"                                         __ "^ this is a pair of parenthesis
   | | |                       ||__________________________________________|_||
   | | |                       |___________________________________________|_||
   | | |                                                                   | |
   | | |                                                                   this is a pair of parenthesis
   | | |                                                                     |
   | | |                                                                     this is a string
06 | | |         } else if n == 1 {
   | | |_________^                ^
   | |  _________|________________|
   | | |         |
   | | |         this is a pair of braces
07 | | |                 return 1;
08 | | |         }
   | | |_________^ this is a pair of braces
09 | |   
10 | |           let mut sum = 0;
11 | |           let mut last = 0;
12 | |           let mut curr = 1;
13 | |           for _i in 1..n {
   | |  ________________________^
14 | | |                 sum = last + curr;
15 | | |                 last = curr;
16 | | |                 curr = sum;
17 | | |         }
   | | |_________^ this is a pair of braces
18 | |           sum
19 | |   }
   | |___^ this is a pair of braces

Structs§

Enums§

  • Highlight format description.