1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! display_list module stores the output model for the snippet.
//!
//! `DisplayList` is a central structure in the crate, which contains
//! the structured list of lines to be displayed.
//!
//! It is made of two types of lines: `Source` and `Raw`. All `Source` lines
//! are structured using four columns:
//!
//! ```text
//!  /------------ (1) Line number column.
//!  |  /--------- (2) Line number column delimiter.
//!  |  | /------- (3) Inline marks column.
//!  |  | |   /--- (4) Content column with the source and annotations for slices.
//!  |  | |   |
//! =============================================================================
//! error[E0308]: mismatched types
//!    --> src/format.rs:51:5
//!     |
//! 151 | /   fn test() -> String {
//! 152 | |       return "test";
//! 153 | |   }
//!     | |___^ error: expected `String`, for `&str`.
//!     |
//! ```
//!
//! The first two lines of the example above are `Raw` lines, while the rest
//! are `Source` lines.
//!
//! `DisplayList` does not store column alignment information, and those are
//! only calculated by the `DisplayListFormatter` using information such as
//! styling.
//!
//! The above snippet has been built out of the following structure:
//!
//! ```
//! use annotate_snippets::display_list::*;
//!
//! let dl = DisplayList {
//!     body: vec![
//!         DisplayLine::Raw(DisplayRawLine::Annotation {
//!             annotation: Annotation {
//!                 annotation_type: DisplayAnnotationType::Error,
//!                 id: Some("E0308".to_string()),
//!                 label: vec![
//!                     DisplayTextFragment {
//!                         content: "mismatched types".to_string(),
//!                         style: DisplayTextStyle::Regular,
//!                     }
//!                 ]
//!             },
//!             source_aligned: false,
//!             continuation: false,
//!         }),
//!         DisplayLine::Raw(DisplayRawLine::Origin {
//!             path: "src/format.rs".to_string(),
//!             pos: Some((51, 5)),
//!             header_type: DisplayHeaderType::Initial,
//!         }),
//!         DisplayLine::Source {
//!             lineno: Some(151),
//!             inline_marks: vec![
//!                 DisplayMark {
//!                     mark_type: DisplayMarkType::AnnotationStart,
//!                     annotation_type: DisplayAnnotationType::Error,
//!                 }
//!             ],
//!             line: DisplaySourceLine::Content {
//!                 text: "  fn test() -> String {".to_string(),
//!                 range: (0, 24)
//!             }
//!         },
//!         DisplayLine::Source {
//!             lineno: Some(152),
//!             inline_marks: vec![
//!                 DisplayMark {
//!                     mark_type: DisplayMarkType::AnnotationThrough,
//!                     annotation_type: DisplayAnnotationType::Error,
//!                 }
//!             ],
//!             line: DisplaySourceLine::Content {
//!                 text: "      return \"test\";".to_string(),
//!                 range: (25, 46)
//!             }
//!         },
//!         DisplayLine::Source {
//!             lineno: Some(153),
//!             inline_marks: vec![
//!                 DisplayMark {
//!                     mark_type: DisplayMarkType::AnnotationThrough,
//!                     annotation_type: DisplayAnnotationType::Error,
//!                 }
//!             ],
//!             line: DisplaySourceLine::Content {
//!                 text: "  }".to_string(),
//!                 range: (47, 51)
//!             }
//!         },
//!         DisplayLine::Source {
//!             lineno: None,
//!             inline_marks: vec![],
//!             line: DisplaySourceLine::Annotation {
//!                 annotation: Annotation {
//!                     annotation_type: DisplayAnnotationType::Error,
//!                     id: None,
//!                     label: vec![
//!                         DisplayTextFragment {
//!                             content: "expected `String`, for `&str`.".to_string(),
//!                             style: DisplayTextStyle::Regular,
//!                         }
//!                     ]
//!                 },
//!                 range: (3, 4),
//!                 annotation_type: DisplayAnnotationType::Error,
//!                 annotation_part: DisplayAnnotationPart::MultilineEnd,
//!             }
//!
//!         }
//!     ]
//! };
//! ```
mod from_snippet;
mod structs;

pub use self::structs::*;