Struct lsp_document::Pos[][src]

pub struct Pos {
    pub line: u32,
    pub col: u32,
}
Expand description

Native position inside a text document/string. Points to a valid position before the character inside a UTF8-encoded string.

Why use Pos instead of raw usize offset

This depends on the use-case. Often raw usize or a newtype wrapper around usize is sufficient. However, raw byte offsets are not stable at all when a text document changes.

Usually, a text document is an input to later stages of the pipelines. Let’s take a simple incremental pipeline:

text: string ->
 symbols: Symbol { ..., start: usize, end: usize } ->
 diagnostics: Diag { ..., start: usize, end: usize }

Now, any change to text on line N will shift all start and end offsets, which will invalidate all symbols and diagnostics following the change and require recomputation.

However, if start and end are Poses then only the line where the change was made is affected. Symbols and diagnostic for other lines won’t be invalidated.

Fields

line: u32

0-indexed line inside the text document.

col: u32

0-indexed byte offset from the beginning of the. The offset is at a valid char boundary.

Implementations

Create a new Pos. This method shouldn’t be required to use most of the time!

line is 0-indexed, col is a 0-indexed byte-offset from the beginning of the line to a valid char position.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.