3
3
` annotate-snippets ` is a Rust library for annotation of programming code slices.
4
4
5
5
[ ![ crates.io] ( https://img.shields.io/crates/v/annotate-snippets.svg )] ( https://crates.io/crates/annotate-snippets )
6
+ [ ![ documentation] ( https://img.shields.io/badge/docs-master-blue.svg )] [ Documentation ]
6
7
![ build status] ( https://github.com/rust-lang/annotate-snippets-rs/actions/workflows/ci.yml/badge.svg )
7
8
8
9
The library helps visualize meta information annotating source code slices.
9
10
It takes a data structure called ` Snippet ` on the input and produces a ` String `
10
11
which may look like this:
11
12
12
- ``` text
13
- error[E0308]: mismatched types
14
- --> src/format.rs:52:1
15
- |
16
- 51 | ) -> Option<String> {
17
- | -------------- expected `Option<String>` because of return type
18
- 52 | / for ann in annotations {
19
- 53 | | match (ann.range.0, ann.range.1) {
20
- 54 | | (None, None) => continue,
21
- 55 | | (Some(start), Some(end)) if start > end_index => continue,
22
- ... |
23
- 71 | | }
24
- 72 | | }
25
- | |_____^ expected enum `std::option::Option`, found ()
26
- ```
27
-
28
- [ Documentation] [ ]
29
-
30
- [ Documentation ] : https://docs.rs/annotate-snippets/
31
-
32
- Usage
33
- -----
34
-
35
- ``` rust
36
- use annotate_snippets :: {Annotation , AnnotationType , Renderer , Slice , Snippet , SourceAnnotation };
37
-
38
- fn main () {
39
- let snippet = Snippet {
40
- title : Some (Annotation {
41
- label : Some (" expected type, found `22`" ),
42
- id : None ,
43
- annotation_type : AnnotationType :: Error ,
44
- }),
45
- footer : vec! [],
46
- slices : vec! [Slice {
47
- source : r # " annotations: vec![SourceAnnotation {
48
- label: "expected struct `annotate_snippets::snippet::Slice`, found reference"
49
- ,
50
- range: <22, 25>," # ,
51
- line_start : 26 ,
52
- origin : Some (" examples/footer.rs" ),
53
- fold : true ,
54
- annotations : vec! [
55
- SourceAnnotation {
56
- label : "" ,
57
- annotation_type : AnnotationType :: Error ,
58
- range : (193 , 195 ),
59
- },
60
- SourceAnnotation {
61
- label : " while parsing this struct" ,
62
- annotation_type : AnnotationType :: Info ,
63
- range : (34 , 50 ),
64
- },
65
- ],
66
- }],
67
- };
68
-
69
- let renderer = Renderer :: plain ();
70
- println! (" {}" , renderer . render (snippet ));
71
- }
72
- ```
13
+ ![ Screenshot] ( ./examples/expected_type.svg )
73
14
74
15
Local Development
75
16
-----------------
@@ -80,3 +21,5 @@ Local Development
80
21
When submitting a PR please use [ ` cargo fmt ` ] [ ] (nightly).
81
22
82
23
[ `cargo fmt` ] : https://github.com/rust-lang/rustfmt
24
+
25
+ [ Documentation ] : https://docs.rs/annotate-snippets/
0 commit comments