Struct regex_syntax::error::Spans[][src]

struct Spans<'p> {
    pattern: &'p str,
    line_number_width: usize,
    by_line: Vec<Vec<Span>>,
    multi_line: Vec<Span>,
}

This type represents an arbitrary number of error spans in a way that makes it convenient to notate the regex pattern. ("Notate" means "point out exactly where the error occurred in the regex pattern.")

Technically, we can only ever have two spans given our current error structure. However, after toiling with a specific algorithm for handling two spans, it became obvious that an algorithm to handle an arbitrary number of spans was actually much simpler.

Fields

The original regex pattern string.

The total width that should be used for line numbers. The width is used for left padding the line numbers for alignment.

A value of 0 means line numbers should not be displayed. That is, the pattern is itself only one line.

All error spans that occur on a single line. This sequence always has length equivalent to the number of lines in pattern, where the index of the sequence represents a line number, starting at 0. The spans in each line are sorted in ascending order.

All error spans that occur over one or more lines. That is, the start and end position of the span have different line numbers. The spans are sorted in ascending order.

Methods

impl<'p> Spans<'p>
[src]

Build a sequence of spans from a formatter.

Add the given span to this sequence, putting it in the right place.

Notate the pattern string with carents (^) pointing at each span location. This only applies to spans that occur within a single line.

Return notes for the line indexed at i (zero-based). If there are no spans for the given line, then None is returned. Otherwise, an appropriately space padded string with correctly positioned ^ is returned, accounting for line numbers.

Left pad the given line number with spaces such that it is aligned with other line numbers.

Return the line number padding beginning at the start of each line of the pattern.

If the pattern is only one line, then this returns a fixed padding for visual indentation.

Auto Trait Implementations

impl<'p> Send for Spans<'p>

impl<'p> Sync for Spans<'p>