commit | 1a15f7cdd759c46e5975674bc7e17f9d6773d1b2 | [log] [tgz] |
---|---|---|
author | Andrew Walbran <qwandor@google.com> | Thu Oct 19 21:16:02 2023 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Thu Oct 19 21:16:02 2023 +0000 |
tree | 6a563dd6ee57d2493ae4879184315ae449dd8208 | |
parent | fac4cf18cca9b1d5ff24b4278f587e8ba2eac7b6 [diff] | |
parent | 74ba4b37eb5eedad15ec2b41b5ef4595efd3bf32 [diff] |
Migrate to cargo_embargo. am: 865991ca32 am: fd9cad5c95 am: 74ba4b37eb Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/annotate-snippets/+/2796413 Change-Id: I56e747cbd9d23ef70dcf5371b5bd59a5bc1e79fd Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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).