pub struct SourceMap { /* private fields */ }Expand description
Generated by the preprocessor: a map from a line number in the preprocessed,
unified source (Span) back to the original input file and line it came
from. This lets a consumer work backwards from a parsed element’s Span
to the file and line the author actually wrote.
The map is stored as a sparse, sorted list of segments. Each segment anchors
one preprocessed line to an origin (file, line); the lines that follow it
map by simple offset until the next segment. A segment also records the
Fidelity of the preprocessed line relative to its origin – whether the
preprocessor rewrote the line content (so a column can no longer be mapped
back faithfully) or left it verbatim. All line numbers are 1-based.
Origin file names are interned: a file included many times, or re-anchored many times, stores its path only once.
Implementations§
Source§impl SourceMap
impl SourceMap
Sourcepub fn original_file_and_line(&self, key: usize) -> Option<SourceLine>
pub fn original_file_and_line(&self, key: usize) -> Option<SourceLine>
Sourcepub fn origin_at(&self, line: usize, col: usize) -> Origin<'_>
pub fn origin_at(&self, line: usize, col: usize) -> Origin<'_>
Translate a 1-based (line, column) position in the preprocessed source
back to its Origin in the original input files.
col counts Unicode scalar values, as Span::col does. It is carried
through to Origin::col only when the line is Fidelity::Verbatim;
otherwise Origin::col is None. See Origin for the column-unit
contract.