Struct Pos Copy item path Source 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 Pos es then only the line where the
change was made is affected. Symbols and diagnostic for other lines won’t be
invalidated.
0-indexed line inside the text document.
0-indexed byte offset from the beginning of the line.
The offset is at a valid char boundary.
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 .
Performs copy-assignment from
source.
Read more Formats the value using the given formatter.
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 Tests for self and other values to be equal, and is used by ==.
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more 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.