#[non_exhaustive]pub struct Location {
pub absolute_start: usize,
pub absolute_end: usize,
pub start: Position,
pub end: Position,
}Expand description
A Location represents a location in a document.
After parsing, line and column positions refer to the original source, including
content from nested and partial includes. Each Position carries its own include
chain in file; primary-input positions use None.
Byte offsets normally refer to each endpoint’s original file. Reindented includes are an exception: their byte offsets remain in preprocessed coordinates. Use the line and column to locate that content in its original file.
A span can cross files. Self::byte_len returns None in that case because the
offsets use different coordinate spaces. JSON contains line, column, and include
chain only; it omits byte offsets.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.absolute_start: usizeThe absolute start position of the location.
absolute_end: usizeThe absolute end position of the location.
start: PositionThe start position of the location.
end: PositionThe end position of the location.
Implementations§
Source§impl Location
impl Location
Sourcepub fn point(position: Position) -> Self
pub fn point(position: Position) -> Self
A zero-width location at a single position (start == end), used for
point diagnostics that only know a line/column. Byte offsets are 0.
Sourcepub fn byte_len(&self) -> Option<usize>
pub fn byte_len(&self) -> Option<usize>
Byte length of this location (absolute_end - absolute_start + 1, end inclusive),
but only when both boundaries are in the same file (start.file == end.file).
Returns None for a span that crosses a file boundary: its absolute_start and
absolute_end live in different files’ coordinate spaces, so subtracting them is
meaningless. Prefer this over subtracting absolute_* directly — it can’t silently
produce a garbage length across files. For a cross-file span, locate each endpoint
via its own file/line instead.
Sourcepub fn validate(&self, input: &str) -> Result<(), String>
pub fn validate(&self, input: &str) -> Result<(), String>
Validates that this location satisfies all invariants.
Checks:
absolute_start <= absolute_end(valid range)absolute_end <= input.len()(within bounds)- Both offsets are on UTF-8 character boundaries
§Errors
Returned as strings for easier debugging.