pub struct LineIndex { /* private fields */ }Expand description
Precomputed line-start offset table for O(log n) line/column ↔ byte offset conversion.
Implementations§
Source§impl LineIndex
impl LineIndex
pub fn new(text: &str) -> Self
pub fn line_count(&self) -> u32
pub fn text_len(&self) -> u32
Sourcepub fn offset_to_position(
&self,
text: &str,
offset: usize,
) -> Result<Position, TextViewError>
pub fn offset_to_position( &self, text: &str, offset: usize, ) -> Result<Position, TextViewError>
Convert a byte offset to a 0-based line/column position.
Sourcepub fn position_to_offset(
&self,
text: &str,
position: Position,
) -> Result<usize, TextViewError>
pub fn position_to_offset( &self, text: &str, position: Position, ) -> Result<usize, TextViewError>
Convert a 0-based line/column position to a byte offset.
Sourcepub fn line_range(&self, line: u32) -> Result<TextRange, TextViewError>
pub fn line_range(&self, line: u32) -> Result<TextRange, TextViewError>
Return the byte range of a line excluding its trailing newline.
Sourcepub fn line_range_with_newline(
&self,
line: u32,
) -> Result<TextRange, TextViewError>
pub fn line_range_with_newline( &self, line: u32, ) -> Result<TextRange, TextViewError>
Return the byte range of a line including its trailing newline.
Sourcepub fn line_of_offset(&self, offset: usize) -> Result<u32, TextViewError>
pub fn line_of_offset(&self, offset: usize) -> Result<u32, TextViewError>
Return the 0-based line number that contains the given byte offset.
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