pub struct LineIndex { /* private fields */ }Expand description
Line index for byte <-> (line, col) mapping.
Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub fn byte_to_position(&self, byte: usize) -> (usize, usize)
pub fn byte_to_position(&self, byte: usize) -> (usize, usize)
Convert a byte offset to (line, column) using byte columns.
Sourcepub fn position_to_byte(&self, line: usize, column: usize) -> Option<usize>
pub fn position_to_byte(&self, line: usize, column: usize) -> Option<usize>
Convert (line, column) back to byte offset.
Returns None when the line is out of range or when the column extends
past the end of the line (including the newline character, but not the
start of the next line).
Sourcepub fn position_to_byte_checked(
&self,
line: usize,
column: usize,
) -> Option<usize>
pub fn position_to_byte_checked( &self, line: usize, column: usize, ) -> Option<usize>
Convert (line, column) back to byte offset, returning None when
the column crosses the line boundary.
The newline character at the end of a line is the last addressable
column on that line. The byte at next_line_start belongs to the
next line and is therefore out of range.
Trait Implementations§
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