commit | 35e8072e74f9e9fbf7a8244b75a6672b26c5daa7 | [log] [tgz] |
---|---|---|
author | James Farrell <[email protected]> | Wed Aug 14 13:21:26 2024 +0000 |
committer | James Farrell <[email protected]> | Wed Aug 14 13:21:26 2024 +0000 |
tree | a731588065341b2a2f706d3e4a907d6ff1e8d610 | |
parent | 6b091502636d68dfb97b117defeb5c0e88291c07 [diff] |
Migrate 10 crates to monorepo ahash aho-corasick android_logger android_log-sys anes annotate-snippets argh argh_derive argh_shared ash Bug: 339424309 Test: treehugger Change-Id: Ie720619b1009d02297acf7b9d68ae72d481fa36b
annotate-snippets
is a Rust library for annotation of programming code slices.
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 ()
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); }
cargo build cargo test
When submitting a PR please use cargo fmt
(nightly).