Platform Tools Release 34.0.5 (10900879)
Snap for 10900817 from feb8fd5a46b48fc8ed6c1e5969de0dbfa3114b40 to sdk-release

Change-Id: I4ac65cc909b1f7d4348a410ee0863b9318fb5d8f
tree: 6c82db5340d7d28a5908286da4ae91001c043b4e
  1. benches/
  2. examples/
  3. src/
  4. tests/
  5. .cargo_vcs_info.json
  6. .gitignore
  7. .travis.yml
  8. Android.bp
  9. Cargo.toml
  10. Cargo.toml.orig
  11. cargo2android.json
  12. CHANGELOG.md
  13. LICENSE-APACHE
  14. LICENSE-MIT
  15. METADATA
  16. MODULE_LICENSE_APACHE2
  17. OWNERS
  18. README.md
README.md

annotate-snippets

annotate-snippets is a Rust library for annotation of programming code slices.

crates.io Build Status Coverage Status

The library helps visualize meta information annotating source code slices. It takes a data structure called Snippet on the input and produces a String which may look like this:

error[E0308]: mismatched types
  --> src/format.rs:52:1
   |
51 |   ) -> Option<String> {
   |        -------------- expected `Option<String>` because of return type
52 | /     for ann in annotations {
53 | |         match (ann.range.0, ann.range.1) {
54 | |             (None, None) => continue,
55 | |             (Some(start), Some(end)) if start > end_index => continue,
...  |
71 | |         }
72 | |     }
   | |_____^ expected enum `std::option::Option`, found ()

Documentation

Usage

use annotate_snippets::{
    display_list::{DisplayList, FormatOptions},
    snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
};

fn main() {
    let snippet = Snippet {
        title: Some(Annotation {
            label: Some("expected type, found `22`"),
            id: None,
            annotation_type: AnnotationType::Error,
        }),
        footer: vec![],
        slices: vec![Slice {
            source: r#"                annotations: vec![SourceAnnotation {
                label: "expected struct `annotate_snippets::snippet::Slice`, found reference"
                    ,
                range: <22, 25>,"#,
            line_start: 26,
            origin: Some("examples/footer.rs"),
            fold: true,
            annotations: vec![
                SourceAnnotation {
                    label: "",
                    annotation_type: AnnotationType::Error,
                    range: (187, 189),
                },
                SourceAnnotation {
                    label: "while parsing this struct",
                    annotation_type: AnnotationType::Info,
                    range: (34, 50),
                },
            ],
        }],
        opt: FormatOptions {
            color: true,
            ..Default::default()
        },
    };

    let dl = DisplayList::from(snippet);
    println!("{}", dl);
}

Local Development

cargo build
cargo test

When submitting a PR please use cargo fmt (nightly).