20 releases

new 0.11.0 Mar 15, 2024
0.10.1 Jan 4, 2024
0.10.0 Dec 13, 2023
0.9.2 Oct 30, 2023
0.1.0 May 22, 2018

#13 in Programming languages

Download history 43945/week @ 2023-11-27 40336/week @ 2023-12-04 43300/week @ 2023-12-11 37748/week @ 2023-12-18 26755/week @ 2023-12-25 35303/week @ 2024-01-01 47102/week @ 2024-01-08 57999/week @ 2024-01-15 51345/week @ 2024-01-22 57320/week @ 2024-01-29 67134/week @ 2024-02-05 64693/week @ 2024-02-12 69594/week @ 2024-02-19 65207/week @ 2024-02-26 72789/week @ 2024-03-04 34015/week @ 2024-03-11

248,437 downloads per month
Used in 149 crates (35 directly)

Apache-2.0/MIT

68KB
1.5K SLoC

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).


lib.rs:

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

Dependencies

~110KB