@@ -35,49 +35,47 @@ Usage
35
35
36
36
``` rust
37
37
use annotate_snippets :: {
38
- display_list :: DisplayList ,
39
- formatter :: DisplayListFormatter ,
38
+ display_list :: {DisplayList , FormatOptions },
40
39
snippet :: {Annotation , AnnotationType , Slice , Snippet , SourceAnnotation },
41
40
};
42
41
43
42
fn main () {
44
43
let snippet = Snippet {
45
44
title : Some (Annotation {
46
- label : Some (" expected type, found `22`" . to_string () ),
45
+ label : Some (" expected type, found `22`" ),
47
46
id : None ,
48
47
annotation_type : AnnotationType :: Error ,
49
48
}),
50
49
footer : vec! [],
51
- slices : vec! [
52
- Slice {
53
- source : r # "
54
- This is an example
55
- content of the slice
56
- which will be annotated
57
- with the list of annotations below.
58
- " # . to_string () ,
59
- line_start : 26 ,
60
- origin : Some ( " examples/example.txt " . to_string ()),
61
- fold : false ,
62
- annotations : vec! [
63
- SourceAnnotation {
64
- label : " Example error annotation " . to_string () ,
65
- annotation_type : AnnotationType :: Error ,
66
- range : ( 13 , 18 ) ,
67
- } ,
68
- SourceAnnotation {
69
- label : " and here's a warning " . to_string () ,
70
- annotation_type : AnnotationType :: Warning ,
71
- range : ( 34 , 50 ) ,
72
- },
73
- ] ,
74
- },
75
- ] ,
50
+ slices : vec! [Slice {
51
+ source : r # " annotations: vec![SourceAnnotation {
52
+ label: "expected struct `annotate_snippets::snippet::Slice`, found reference "
53
+ ,
54
+ range: <22, 25>, " # ,
55
+ line_start : 26 ,
56
+ origin : Some ( " examples/footer.rs " ),
57
+ fold : true ,
58
+ annotations : vec! [
59
+ SourceAnnotation {
60
+ label : "" ,
61
+ annotation_type : AnnotationType :: Error ,
62
+ range : ( 205 , 207 ),
63
+ } ,
64
+ SourceAnnotation {
65
+ label : " while parsing this struct " ,
66
+ annotation_type : AnnotationType :: Info ,
67
+ range : ( 34 , 50 ),
68
+ } ,
69
+ ] ,
70
+ }] ,
71
+ opt : FormatOptions {
72
+ color : true ,
73
+ .. Default :: default ()
74
+ } ,
76
75
};
77
76
78
77
let dl = DisplayList :: from (snippet );
79
- let dlf = DisplayListFormatter :: new (true , false );
80
- println! (" {}" , dlf . format (& dl ));
78
+ println! (" {}" , dl );
81
79
}
82
80
```
83
81
0 commit comments