pub struct LineIndex { /* private fields */ }Expand description
A precomputed map from byte offsets to line/column positions for one source
string. Build it once with LineIndex::new, then query repeatedly.
Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub fn new(source: &str) -> Self
pub fn new(source: &str) -> Self
Build a line index for source, scanning its line breaks
(\n, \r, and \r\n).
Sourcepub fn position(&self, offset: usize) -> LinePosition
pub fn position(&self, offset: usize) -> LinePosition
Translate a byte offset into its 1-based line and column (clamped to the
end of the source).
Sourcepub fn span(&self, span: Span) -> (LinePosition, LinePosition)
pub fn span(&self, span: Span) -> (LinePosition, LinePosition)
Translate a Span into its start and end LinePositions.
Trait Implementations§
impl Eq for LineIndex
impl StructuralPartialEq for LineIndex
Auto Trait Implementations§
impl Freeze for LineIndex
impl RefUnwindSafe for LineIndex
impl Send for LineIndex
impl Sync for LineIndex
impl Unpin for LineIndex
impl UnsafeUnpin for LineIndex
impl UnwindSafe for LineIndex
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