Struct textpos::TextPosition
source · [−]pub struct TextPosition { /* private fields */ }Expand description
Points to a certain character.
A TextPosition also keeps track of the human-interpretable position (ie.
line/column).
Implementations
sourceimpl TextPosition
impl TextPosition
sourcepub fn new(idx: usize, line: usize, col: usize) -> Self
pub fn new(idx: usize, line: usize, col: usize) -> Self
Crate a new TextPosition from raw parts
sourcepub fn line(&self) -> usize
pub fn line(&self) -> usize
The line this position is on. 1 is the first line.
This is always equals to the number of inc_line() calls made on this
position.
sourcepub fn col(&self) -> usize
pub fn col(&self) -> usize
The column this position is on. 1 is the first column.
This is always equals to the number of inc_col() calls made on this
position after the last inc_line() call.
sourcepub fn previous(&self) -> TextPosition
pub fn previous(&self) -> TextPosition
Return the previous position.
Note, that when this is used on a position that is on the first column, then this will yield a previous position at the zeroth column (which doesn’t exist, 1 is the first column). Conceptually this represents the last character of the previous line, ie. the newline character.
Also, this function may not be called on a zeroth-column position or on a character with index 0.
Due to these peculiarities, the returned position should not be reused for further computations, only for formatting purposes.
Trait Implementations
sourceimpl Clone for TextPosition
impl Clone for TextPosition
sourcefn clone(&self) -> TextPosition
fn clone(&self) -> TextPosition
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for TextPosition
impl Debug for TextPosition
sourceimpl Default for TextPosition
impl Default for TextPosition
sourceimpl Display for TextPosition
impl Display for TextPosition
sourceimpl Ord for TextPosition
impl Ord for TextPosition
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<TextPosition> for TextPosition
impl PartialEq<TextPosition> for TextPosition
sourcefn eq(&self, other: &TextPosition) -> bool
fn eq(&self, other: &TextPosition) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourceimpl PartialOrd<TextPosition> for TextPosition
impl PartialOrd<TextPosition> for TextPosition
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl Eq for TextPosition
impl StructuralEq for TextPosition
impl StructuralPartialEq for TextPosition
Auto Trait Implementations
impl RefUnwindSafe for TextPosition
impl Send for TextPosition
impl Sync for TextPosition
impl Unpin for TextPosition
impl UnwindSafe for TextPosition
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more