1 use annotate_snippets::{
2     display_list::{DisplayList, FormatOptions},
3     snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
4 };
5 
main()6 fn main() {
7     let snippet = Snippet {
8         slices: vec![Slice {
9             source: r#") -> Option<String> {
10     for ann in annotations {
11         match (ann.range.0, ann.range.1) {
12             (None, None) => continue,
13             (Some(start), Some(end)) if start > end_index => continue,
14             (Some(start), Some(end)) if start >= start_index => {
15                 let label = if let Some(ref label) = ann.label {
16                     format!(" {}", label)
17                 } else {
18                     String::from("")
19                 };
20 
21                 return Some(format!(
22                     "{}{}{}",
23                     " ".repeat(start - start_index),
24                     "^".repeat(end - start),
25                     label
26                 ));
27             }
28             _ => continue,
29         }
30     }"#,
31             line_start: 51,
32             origin: Some("src/format.rs"),
33             fold: false,
34             annotations: vec![
35                 SourceAnnotation {
36                     label: "expected `Option<String>` because of return type",
37                     annotation_type: AnnotationType::Warning,
38                     range: (5, 19),
39                 },
40                 SourceAnnotation {
41                     label: "expected enum `std::option::Option`",
42                     annotation_type: AnnotationType::Error,
43                     range: (26, 724),
44                 },
45             ],
46         }],
47         title: Some(Annotation {
48             label: Some("mismatched types"),
49             id: Some("E0308"),
50             annotation_type: AnnotationType::Error,
51         }),
52         footer: vec![],
53         opt: FormatOptions {
54             color: true,
55             ..Default::default()
56         },
57     };
58 
59     let dl = DisplayList::from(snippet);
60     println!("{}", dl);
61 }
62