pub struct Position {
pub line: usize,
pub column: usize,
}Expand description
A position in a document.
Lines and columns are 1-based. Columns count Unicode scalar values in the
line’s content; they are not UTF-8 byte offsets, grapheme clusters, or
display cells. A line containing "café" therefore ends at column 5.
The end-of-line column is immediately before the complete line terminator.
Column 1 of the following line is immediately after it. Consequently CRLF
is atomic: no valid Position can point between \r and \n.
EOF is represented by the final line’s end column when the document has no trailing terminator, or by column 1 of the next line when it does.
Fields§
§line: usizeLine number (1-based)
column: usizeColumn number (1-based)
Implementations§
Source§impl Position
impl Position
Sourcepub const fn line_start(line: usize) -> Self
pub const fn line_start(line: usize) -> Self
Return column 1 of line.
Sourcepub fn line_end(line: usize, line_content: &str) -> Self
pub fn line_end(line: usize, line_content: &str) -> Self
Return the position immediately after line_content and before its
terminator, if any.
Sourcepub fn from_byte_offset_in_line(
line: usize,
line_content: &str,
byte_offset: usize,
) -> Option<Self>
pub fn from_byte_offset_in_line( line: usize, line_content: &str, byte_offset: usize, ) -> Option<Self>
Convert a zero-based UTF-8 byte offset within one line to a scalar-based document position.
Returns None if byte_offset is outside line_content or is not a
UTF-8 character boundary.
Sourcepub fn to_byte_offset(self, content: &str) -> Option<usize>
pub fn to_byte_offset(self, content: &str) -> Option<usize>
Resolve this position to a zero-based UTF-8 byte offset in content.
Invalid line or column numbers, including positions inside CRLF, return
None.
Sourcepub fn from_byte_offset(content: &str, byte_offset: usize) -> Option<Self>
pub fn from_byte_offset(content: &str, byte_offset: usize) -> Option<Self>
Convert a zero-based UTF-8 byte offset in content to a document
position.
Offsets outside the document, in the middle of a UTF-8 scalar, or
between the two bytes of a CRLF terminator return None.
Trait Implementations§
impl Copy for Position
impl Eq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnsafeUnpin for Position
impl UnwindSafe for Position
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.