]> git.proxmox.com Git - rustc.git/blob - vendor/annotate-snippets/src/snippet.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / vendor / annotate-snippets / src / snippet.rs
1 //! Structures used as an input for the library.
2 //!
3 //! Example:
4 //!
5 //! ```
6 //! use annotate_snippets::snippet::*;
7 //!
8 //! Snippet {
9 //! title: Some(Annotation {
10 //! label: Some("mismatched types".to_string()),
11 //! id: None,
12 //! annotation_type: AnnotationType::Error,
13 //! }),
14 //! footer: vec![],
15 //! slices: vec![
16 //! Slice {
17 //! source: "Foo".to_string(),
18 //! line_start: 51,
19 //! origin: Some("src/format.rs".to_string()),
20 //! fold: false,
21 //! annotations: vec![],
22 //! },
23 //! Slice {
24 //! source: "Faa".to_string(),
25 //! line_start: 129,
26 //! origin: Some("src/display.rs".to_string()),
27 //! fold: false,
28 //! annotations: vec![],
29 //! },
30 //! ],
31 //! };
32 //! ```
33 /// Primary structure provided for formatting
34 #[derive(Debug, Clone)]
35 pub struct Snippet {
36 pub title: Option<Annotation>,
37 pub footer: Vec<Annotation>,
38 pub slices: Vec<Slice>,
39 }
40
41 /// Structure containing the slice of text to be annotated and
42 /// basic information about the location of the slice.
43 #[derive(Debug, Clone)]
44 pub struct Slice {
45 pub source: String,
46 pub line_start: usize,
47 pub origin: Option<String>,
48 pub annotations: Vec<SourceAnnotation>,
49 /// If set explicitly to `true`, the snippet will fold
50 /// parts of the slice that don't contain any annotations.
51 pub fold: bool,
52 }
53
54 /// Types of annotations.
55 #[derive(Debug, Clone, Copy)]
56 pub enum AnnotationType {
57 /// Error annotations are displayed using red color and "^" character.
58 Error,
59 /// Warning annotations are displayed using blue color and "-" character.
60 Warning,
61 Info,
62 Note,
63 Help,
64 }
65
66 /// An annotation for a `Slice`.
67 #[derive(Debug, Clone)]
68 pub struct SourceAnnotation {
69 pub range: (usize, usize),
70 pub label: String,
71 pub annotation_type: AnnotationType,
72 }
73
74 /// An annotation for a `Snippet`.
75 #[derive(Debug, Clone)]
76 pub struct Annotation {
77 /// Identifier of the annotation. Usually error code like "E0308".
78 pub id: Option<String>,
79 pub label: Option<String>,
80 pub annotation_type: AnnotationType,
81 }