pub struct SourceMap { /* private fields */ }Expand description
Pre-computed index of line-start byte offsets for a source string.
Construction is O(n) in the source length. Each lookup is O(log n) in the number of lines (binary search), which is effectively O(1) for typical files.
Implementations§
Source§impl SourceMap
impl SourceMap
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Total number of lines in the source.
Sourcepub fn line_start(&self, line: u32) -> Option<u32>
pub fn line_start(&self, line: u32) -> Option<u32>
Byte offset where the given 0-based line starts.
Returns None if the line is out of range.
Sourcepub fn offset_to_line_col(&self, offset: u32) -> LineCol
pub fn offset_to_line_col(&self, offset: u32) -> LineCol
Convert a byte offset to a 0-based line/column.
If offset is past the end of the source, the position is clamped to
the last line.
Sourcepub fn span_to_line_col(&self, span: Span) -> LineColSpan
pub fn span_to_line_col(&self, span: Span) -> LineColSpan
Convert a Span to a start/end LineColSpan.
Sourcepub fn line_col_to_offset(&self, lc: LineCol) -> Option<u32>
pub fn line_col_to_offset(&self, lc: LineCol) -> Option<u32>
Convert a 0-based line/column back to a byte offset.
Returns None if the line is out of range.
Auto Trait Implementations§
impl Freeze for SourceMap
impl RefUnwindSafe for SourceMap
impl Send for SourceMap
impl Sync for SourceMap
impl Unpin for SourceMap
impl UnsafeUnpin for SourceMap
impl UnwindSafe for SourceMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more