Module annotate_snippets::display_list [] [src]

display_list module stores the output model for the snippet.

DisplayList is a central structure in the crate, which contains the structured list of lines to be displayed.

It is made of two types of lines: Source and Raw. All Source lines are structured using four columns:

 /------------ (1) Line number column.
 |  /--------- (2) Line number column delimiter.
 |  | /------- (3) Inline marks column.
 |  | |   /--- (4) Content column with the source and annotations for slices.
 |  | |   |
=============================================================================
error[E0308]: mismatched types
   --> src/format.rs:51:5
    |
151 | /   fn test() -> String {
152 | |       return "test";
153 | |   }
    | |___^ error: expected `String`, for `&str`.
    |

The first two lines of the example above are Raw lines, while the rest are Source lines.

DisplayList does not store column alignment information, and those are only calculated by the DisplayListFormatter using information such as styling.

The above snippet has been built out of the following structure:

use annotate_snippets::display_list::*;

let dl = DisplayList {
    body: vec![
        DisplayLine::Raw(DisplayRawLine::Annotation {
            annotation: Annotation {
                annotation_type: DisplayAnnotationType::Error,
                id: Some("E0308".to_string()),
                label: vec![
                    DisplayTextFragment {
                        content: "mismatched types".to_string(),
                        style: DisplayTextStyle::Regular,
                    }
                ]
            },
            source_aligned: false,
            continuation: false,
        }),
        DisplayLine::Raw(DisplayRawLine::Origin {
            path: "src/format.rs".to_string(),
            pos: Some((51, 5)),
            header_type: DisplayHeaderType::Initial,
        }),
        DisplayLine::Source {
            lineno: Some(151),
            inline_marks: vec![
                DisplayMark {
                    mark_type: DisplayMarkType::AnnotationStart,
                    annotation_type: DisplayAnnotationType::Error,
                }
            ],
            line: DisplaySourceLine::Content {
                text: "  fn test() -> String {".to_string(),
                range: (0, 24)
            }
        },
        DisplayLine::Source {
            lineno: Some(152),
            inline_marks: vec![
                DisplayMark {
                    mark_type: DisplayMarkType::AnnotationThrough,
                    annotation_type: DisplayAnnotationType::Error,
                }
            ],
            line: DisplaySourceLine::Content {
                text: "      return \"test\";".to_string(),
                range: (25, 46)
            }
        },
        DisplayLine::Source {
            lineno: Some(153),
            inline_marks: vec![
                DisplayMark {
                    mark_type: DisplayMarkType::AnnotationThrough,
                    annotation_type: DisplayAnnotationType::Error,
                }
            ],
            line: DisplaySourceLine::Content {
                text: "  }".to_string(),
                range: (47, 51)
            }
        },
        DisplayLine::Source {
            lineno: None,
            inline_marks: vec![],
            line: DisplaySourceLine::Annotation {
                annotation: Annotation {
                    annotation_type: DisplayAnnotationType::Error,
                    id: None,
                    label: vec![
                        DisplayTextFragment {
                            content: "expected `String`, for `&str`.".to_string(),
                            style: DisplayTextStyle::Regular,
                        }
                    ]
                },
                range: (3, 4),
                annotation_type: DisplayAnnotationType::Error,
                annotation_part: DisplayAnnotationPart::MultilineEnd,
            }

        }
    ]
};

Structs

Annotation

Inline annotation which can be used in either Raw or Source line.

DisplayList

List of lines to be displayed.

DisplayMark

A visual mark used in inline_marks field of the DisplaySourceLine.

DisplayTextFragment

An inline text fragment which any label is composed of.

Enums

DisplayAnnotationPart

An indicator of what part of the annotation a given Annotation is.

DisplayAnnotationType

A type of the Annotation which may impact the sigils, style or text displayed.

DisplayHeaderType

Information whether the header is the initial one or a consequitive one for multi-slice cases.

DisplayLine

A single line used in DisplayList.

DisplayMarkType

A type of the DisplayMark.

DisplayRawLine

Raw line - a line which does not have the lineno part and is not considered a part of the snippet.

DisplaySourceLine

A source line.

DisplayTextStyle

A style for the DisplayTextFragment which can be visually formatted.