pub struct Span { /* private fields */ }Expand description
A half-open byte range [lo, lo + len) within one source file.
A span carries its FileId, which costs four bytes and buys one thing
worth paying for: a span from any file of a compilation reads back
through one SourceMap without a file beside it.
Every span names a real position; a value that may have none holds an
Option<Span>.
Extents are measured in UTF-8 bytes, matching
docs/language/spec/grammar.md’s lexical contract, where token extents
partition the file and their byte lengths sum to its length. Line and column
are a rendering concern and are computed on demand by
SourceFile::line_col.
Implementations§
Source§impl Span
impl Span
Sourcepub fn new(file: FileId, lo: u32, len: u32) -> Self
pub fn new(file: FileId, lo: u32, len: u32) -> Self
Returns the span covering len bytes from lo in file.
§Panics
Panics when lo + len would exceed the u32 range.
Sourcepub fn from_bounds(file: FileId, lo: u32, hi: u32) -> Self
pub fn from_bounds(file: FileId, lo: u32, hi: u32) -> Self
Sourcepub const fn shrink_to_lo(self) -> Self
pub const fn shrink_to_lo(self) -> Self
Returns the empty span at this one’s start.
Sourcepub const fn shrink_to_hi(self) -> Self
pub const fn shrink_to_hi(self) -> Self
Returns the empty span at this one’s end.
Sourcepub fn merge(self, other: Self) -> Self
pub fn merge(self, other: Self) -> Self
Returns the smallest span covering both.
§Panics
Panics when the spans name different files. One span names one file, so there is no honest answer to give instead.