Docs.rs
  • annotate-snippets-0.11.5
    • annotate-snippets 0.11.5
    • Permalink
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • zbraniecki
    • Muscraft
    • Dependencies
      • anstyle ^1.0.4 normal
      • memchr ^2.7.4 normal optional
      • unicode-width ^0.2.0 normal
      • anstream ^0.6.13 dev
      • difference ^2.0.0 dev
      • divan ^0.1.14 dev
      • glob ^0.3.1 dev
      • serde ^1.0.199 dev
      • snapbox ^0.6.0 dev
      • toml ^0.8.0 dev
      • tryfn ^0.2.1 dev
    • Versions
    • 81.48% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate annotate_snippets

annotate_snippets0.11.5

  • All Items

Sections

  • Example
  • features

Crate Items

  • Modules
  • Structs
  • Enums

Crates

  • annotate_snippets

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

use annotate_snippets::{Level, Renderer, Snippet};

fn main() {
    let source = r#"                annotations: vec![SourceAnnotation {
                label: "expected struct `annotate_snippets::snippet::Slice`, found reference"
                    ,
                range: <22, 25>,"#;
    let message = Level::Error.title("expected type, found `22`").snippet(
        Snippet::source(source)
            .line_start(26)
            .origin("examples/footer.rs")
            .fold(true)
            .annotation(
                Level::Error
                    .span(193..195)
                    .label("expected struct `annotate_snippets::snippet::Slice`, found reference"),
            )
            .annotation(Level::Info.span(34..50).label("while parsing this struct")),
    );

    let renderer = Renderer::styled();
    anstream::println!("{}", renderer.render(message));
}
error: expected type, found `22` --> examples/footer.rs:29:25 | 26 | annotations: vec![SourceAnnotation { | ---------------- info: while parsing this struct 27 | label: "expected struct `annotate_snippets::snippet::Slice`, found reference" 28 | , 29 | range: <22, 25>, | ^^ expected struct `annotate_snippets::snippet::Slice`, found reference |

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

Modules§

renderer
The renderer for Messages

Structs§

Annotation
An annotation for a Snippet.
Message
Primary structure provided for formatting
Renderer
A renderer for Messages
Snippet
Structure containing the slice of text to be annotated and basic information about the location of the slice.

Enums§

Level
Types of annotations.

Results

Settings
Help
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.