pub struct LineIndex { /* private fields */ }Expand description
Source text plus a line-start index, supporting byte ↔ Position conversion.
Owns the text so it can serve slices and per-line lookups without the caller
also threading a &str through. This is the same memory profile as the old
RopeC(Rope) (which already duplicated the Source string).
Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub fn new(text: impl Into<String>) -> Self
pub fn new(text: impl Into<String>) -> Self
Build an index over text, scanning once for line breaks (O(n)).
Sourcepub fn len_lines(&self) -> usize
pub fn len_lines(&self) -> usize
Number of lines (a trailing newline counts as starting one more line).
Sourcepub fn line_start(&self, line: usize) -> Option<usize>
pub fn line_start(&self, line: usize) -> Option<usize>
Byte offset at which line starts, or None if out of range. A
one-past-the-end line is not accepted (use [len_bytes] for that).
Sourcepub fn line_byte_range(&self, line: usize) -> Option<Range<usize>>
pub fn line_byte_range(&self, line: usize) -> Option<Range<usize>>
Byte range [start, end) of line, including its trailing newline (if any).
Sourcepub fn line_str(&self, line: usize) -> Option<&str>
pub fn line_str(&self, line: usize) -> Option<&str>
Text of line, including its trailing newline (if any).
Sourcepub fn byte_slice(&self, range: Range<usize>) -> Option<&str>
pub fn byte_slice(&self, range: Range<usize>) -> Option<&str>
Sub-slice by byte range. Returns None for out-of-bounds ranges or
ranges that do not fall on char boundaries.
Sourcepub fn char_at_byte(&self, byte: usize) -> Option<char>
pub fn char_at_byte(&self, byte: usize) -> Option<char>
The char starting at byte offset byte, if byte is a char boundary
within the text.
Sourcepub fn byte_to_position(
&self,
byte: usize,
encoding: PositionEncoding,
) -> Option<Position>
pub fn byte_to_position( &self, byte: usize, encoding: PositionEncoding, ) -> Option<Position>
Convert a byte offset to an LSP Position in the given encoding.
Accepts byte == len_bytes() (end of document). Returns None if byte
is out of range or not on a char boundary.
Sourcepub fn position_to_byte(
&self,
position: Position,
encoding: PositionEncoding,
) -> Option<usize>
pub fn position_to_byte( &self, position: Position, encoding: PositionEncoding, ) -> Option<usize>
Convert an LSP Position (interpreted in encoding) to a byte offset.
A character past the end of its line is clamped to the line’s end (which
keeps the lenient behaviour editors rely on when the cursor sits after the
last character). Returns None only if the line itself is 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more