Skip to main content

LineIndex

Struct LineIndex 

Source
pub struct LineIndex<'a> { /* private fields */ }
Expand description

Maps byte offsets into a source string to line/column coordinates.

Implementations§

Source§

impl<'a> LineIndex<'a>

Source

pub fn new(text: &'a str) -> Self

Source

pub fn line_column(&self, offset: usize) -> LineColumn

Return the one-based human-readable line and column for offset.

Columns are counted in Unicode scalar values, matching Rust chars. Out-of-range offsets clamp to the document end; offsets in the middle of a UTF-8 sequence clamp back to the previous character boundary.

Source

pub fn utf16_position(&self, offset: usize) -> Utf16Position

Return the zero-based line and UTF-16 column for offset.

This is the coordinate system used by LSP. Out-of-range offsets clamp to the document end; offsets in the middle of a UTF-8 sequence clamp back to the previous character boundary.

Source

pub fn utf8_position(&self, offset: usize) -> Utf8Position

Return the zero-based line and UTF-8 byte column for offset.

Source

pub fn end_utf16_position(&self) -> Utf16Position

The UTF-16 position one past the last character.

Source

pub fn end_utf8_position(&self) -> Utf8Position

The UTF-8 position one past the last byte.

Source

pub fn offset_for_utf16_position(&self, position: Utf16Position) -> usize

The byte offset for a zero-based line and UTF-16 column.

Out-of-range lines and columns clamp to the line or document end. A UTF-16 column landing in the middle of a surrogate pair maps to the start of that character.

Source

pub fn offset_for_utf8_position(&self, position: Utf8Position) -> usize

The byte offset for a zero-based line and UTF-8 byte column.

Auto Trait Implementations§

§

impl<'a> Freeze for LineIndex<'a>

§

impl<'a> RefUnwindSafe for LineIndex<'a>

§

impl<'a> Send for LineIndex<'a>

§

impl<'a> Sync for LineIndex<'a>

§

impl<'a> Unpin for LineIndex<'a>

§

impl<'a> UnsafeUnpin for LineIndex<'a>

§

impl<'a> UnwindSafe for LineIndex<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.