Struct regex_syntax::error::Spans

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

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§

§pattern: &'p str

The original regex pattern string.

§line_number_width: usize

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.

§by_line: Vec<Vec<Span>>

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.

§multi_line: Vec<Span>

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.

Implementations§

source§

impl<'p> Spans<'p>

source

fn from_formatter<'e, E: Display>(fmter: &'p Formatter<'e, E>) -> Spans<'p>

Build a sequence of spans from a formatter.

source

fn add(&mut self, span: Span)

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

source

fn notate(&self) -> String

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

source

fn notate_line(&self, i: usize) -> Option<String>

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.

source

fn left_pad_line_number(&self, n: usize) -> String

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

source

fn line_number_padding(&self) -> usize

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> Freeze for Spans<'p>

§

impl<'p> RefUnwindSafe for Spans<'p>

§

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

§

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

§

impl<'p> Unpin for Spans<'p>

§

impl<'p> UnwindSafe for Spans<'p>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.