Crate annotate_snippets
source ·Expand description
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
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 ()
The crate uses a three stage process with two conversions between states:
Snippet --> Renderer --> impl Display
The input type - Snippet 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
Modules§
- The renderer for
Snippet
s
Structs§
- An annotation for a
Snippet
. - A renderer for
Snippet
s - Structure containing the slice of text to be annotated and basic information about the location of the slice.
- Primary structure provided for formatting
- An annotation for a
Slice
.
Enums§
- Types of annotations.