annotate_snippets_builder

Crates.ioannotate_snippets_builder
lib.rsannotate_snippets_builder
version0.1.1
sourcesrc
created_at2022-11-20 00:19:10.705206
updated_at2022-11-20 00:19:10.705206
descriptionBuilder pattern abstraction for the annotate-snippets crate.
homepage
repositoryhttps://github.com/CreatorSiSo/annotate_snippets_builder
max_upload_size
id718764
size10,694
Simon Sommer (CreatorSiSo)

documentation

README

Builder pattern abstraction for the annotate-snippets crate.

use annotate_snippets_builder::{Annotation, AnnotationType, DisplayList, Slice, Snippet};
use stringx::Join;

fn main() {
	let src_1 = include_str!("./lex_invalid.rym").lines().skip(2).join("\n");

	let snippet = Snippet::new()
		.title(
			Annotation::new(AnnotationType::Error)
				.id("E4320")
				.label("Unexpected character"),
		)
		.add_slice(
			Slice {
				source: &src_1,
				line_start: 3,
			}
			.origin("./lex_invalid.rym")
			.annotation((3, 4), AnnotationType::Error, "invalid")
			.annotation((26, 32), AnnotationType::Error, "invalid"),
		)
		.add_slice(
			Slice {
				source: "Ident::Test",
				line_start: 129,
			}
			.origin("src/display.rs")
			.annotation((0, 11), AnnotationType::Warning, "Unused"),
		);

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

How to install.

cargo add annotate_snippets_builder
Commit count: 6

cargo fmt