pub struct LineIndex { /* private fields */ }Expand description
Cached table of line-start byte offsets for one buffer.
Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub fn build(bytes: &[u8]) -> LineIndex
pub fn build(bytes: &[u8]) -> LineIndex
Build the index over bytes (the buffer contents, excluding the NUL
terminator). A line starts at offset 0 and after each \n.
Sourcepub fn line_col(&self, offset: u32) -> (u32, u32)
pub fn line_col(&self, offset: u32) -> (u32, u32)
Return 1-based (line, col) for offset. col is 1-based byte distance
from the line start.
Sourcepub fn line_ref<'a>(&self, bytes: &'a [u8], line: u32) -> &'a [u8] ⓘ
pub fn line_ref<'a>(&self, bytes: &'a [u8], line: u32) -> &'a [u8] ⓘ
Return the slice of bytes for 1-based line, including its trailing
EOL if present. The final line may have no EOL.
Sourcepub fn line_count(&self) -> u32
pub fn line_count(&self) -> u32
Number of lines.
Sourcepub fn line_start(&self, line: u32) -> u32
pub fn line_start(&self, line: u32) -> u32
Byte offset where 1-based line starts (= line_starts[line - 1]).
Panics if line is out of range; callers should guard with line_count().
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