25 releases

0.11.5 Dec 9, 2024
0.11.4 Jun 15, 2024
0.11.2 Apr 27, 2024
0.11.1 Mar 21, 2024
0.1.0 May 22, 2018

#11 in Programming languages

Download history 125612/week @ 2025-01-06 130114/week @ 2025-01-13 123889/week @ 2025-01-20 124632/week @ 2025-01-27 137125/week @ 2025-02-03 137450/week @ 2025-02-10 131994/week @ 2025-02-17 139299/week @ 2025-02-24 127581/week @ 2025-03-03 141133/week @ 2025-03-10 130463/week @ 2025-03-17 129513/week @ 2025-03-24 140707/week @ 2025-03-31 143231/week @ 2025-04-07 157203/week @ 2025-04-14 162470/week @ 2025-04-21

614,146 downloads per month
Used in 319 crates (71 directly)

MIT/Apache

97KB
2K SLoC

A library for formatting of text or programming code snippets.

It's primary purpose is to build an ASCII-graphical representation of the snippet with annotations.

Example

The crate uses a three stage process with two conversions between states:

Message --> Renderer --> impl Display

The input type - [Message] is a structure designed to align with likely output from any parser whose code snippet is to be annotated.

The middle structure - [Renderer] is a structure designed to convert a snippet into an internal structure that is designed to store the snippet data in a way that is easy to format. [Renderer] also handles the user-configurable formatting options, such as color, or margins.

Finally, impl Display into a final String output.

features

  • testing-colors - Makes Renderer::styled colors OS independent, which allows for easier testing when testing colored output. It should be added as a feature in [dev-dependencies], which can be done with the following command:
cargo add annotate-snippets --dev --feature testing-colors

annotate-snippets

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

crates.io documentation build 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:

Screenshot

Local Development

cargo build
cargo test

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

Dependencies

~1.5MB
~23K SLoC