Span in sqlparser::tokenizer - Rust

Skip to main content

pub struct Span {
    pub start: Location,
    pub end: Location,
}
Expand description

A span represents a linear portion of the input string (start, end)

See Spanned for more information.

Start Location (inclusive).

End Location (inclusive).

Source§
Source

Create a new span from a start and end Location

Source

Returns an empty span (0, 0) -> (0, 0)

Empty spans represent no knowledge of source location See Spanned for more information.

Source

Returns the smallest Span that contains both self and other If either span is Span::empty, the other span is returned

§Examples
// line 1, column1 -> line 2, column 5
let span1 = Span::new(Location::new(1, 1), Location::new(2, 5));
// line 2, column 3 -> line 3, column 7
let span2 = Span::new(Location::new(2, 3), Location::new(3, 7));
// Union of the two is the min/max of the two spans
// line 1, column 1 -> line 3, column 7
let union = span1.union(&span2);
assert_eq!(union, Span::new(Location::new(1, 1), Location::new(3, 7)));
Source

Same as Span::union for Option<Span>

If other is None, self is returned

Source

Return the Span::union of all spans in the iterator

If the iterator is empty, an empty span is returned

§Example
let spans = vec![
    Span::new(Location::new(1, 1), Location::new(2, 5)),
    Span::new(Location::new(2, 3), Location::new(3, 7)),
    Span::new(Location::new(3, 1), Location::new(4, 2)),
];
// line 1, column 1 -> line 4, column 2
assert_eq!(
  Span::union_iter(spans),
  Span::new(Location::new(1, 1), Location::new(4, 2))
);

§
§
§
§
§
§