pub struct Index {
pub line: usize,
pub char: usize,
}
Expand description
An index representing the position of a cursor within some text.
Fields§
§line: usize
The byte index of the line upon which the cursor is situated.
char: usize
The index within all possible cursor positions for the line.
For example, for the line foo
, a char
of 1
would indicate the cursor’s position
as f|oo
where |
is the cursor.
Implementations§
source§impl Index
impl Index
sourcepub fn previous_word_start<I>(self, text: &str, line_infos: I) -> Option<Self>
pub fn previous_word_start<I>(self, text: &str, line_infos: I) -> Option<Self>
The cursor index of the beginning of the word (block of non-whitespace) before self
.
If self
is at the beginning of the line, call previous, which returns the last
index position of the previous line, or None if it’s the first line
If self
points to whitespace, skip past that whitespace, then return the index of
the start of the word that precedes the whitespace
If self
is in the middle or end of a word, return the index of the start of that word
sourcepub fn next_word_end<I>(self, text: &str, line_infos: I) -> Option<Self>
pub fn next_word_end<I>(self, text: &str, line_infos: I) -> Option<Self>
The cursor index of the end of the first word (block of non-whitespace) after self
.
If self
is at the end of the text, this returns None
.
If self
is at the end of a line other than the last, this returns the first index of
the next line.
If self
points to whitespace, skip past that whitespace, then return the index of
the end of the word after the whitespace
If self
is in the middle or start of a word, return the index of the end of that word
sourcepub fn previous<I>(self, line_infos: I) -> Option<Self>
pub fn previous<I>(self, line_infos: I) -> Option<Self>
The cursor index that comes before self
.
If self
is at the beginning of the text, this returns None
.
If self
is at the beginning of a line other than the first, this returns the last
index position of the previous line.
If self
is a position other than the start of a line, it will return the position
that is immediately to the left.
sourcepub fn next<I>(self, line_infos: I) -> Option<Self>
pub fn next<I>(self, line_infos: I) -> Option<Self>
The cursor index that follows self
.
If self
is at the end of the text, this returns None
.
If self
is at the end of a line other than the last, this returns the first index of
the next line.
If self
is a position other than the end of a line, it will return the position that
is immediately to the right.
sourcepub fn clamp_to_lines<I>(self, line_infos: I) -> Self
pub fn clamp_to_lines<I>(self, line_infos: I) -> Self
Clamps self
to the given lines.
If self
would lie after the end of the last line, return the index at the end of the
last line.
If line_infos
is empty, returns cursor at line=0 char=0.
Trait Implementations§
source§impl Ord for Index
impl Ord for Index
source§impl PartialEq for Index
impl PartialEq for Index
source§impl PartialOrd for Index
impl PartialOrd for Index
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Index
impl Eq for Index
impl StructuralEq for Index
impl StructuralPartialEq for Index
Auto Trait Implementations§
impl RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl UnwindSafe for Index
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
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, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
source§fn convert_into(self) -> U
fn convert_into(self) -> U
source§fn convert_unclamped_into(self) -> U
fn convert_unclamped_into(self) -> U
source§fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains the unclamped color. Read moresource§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.