pub struct Position {
pub row: usize,
pub col: usize,
}Expand description
A (row, col) location inside a crate::Buffer.
rowis zero-based, in logical lines (newline-separated). Wrapping is a render-only concern; noPositionever points at a display line.colis zero-based, char index within the line — not bytes, not graphemes, not display columns. Width-aware motions go through helpers inmotion.rs; do not synthesizePositionfrom a column count without consulting them. The accompanyingPosition::byte_offsethelper converts a char-indexcolback to a byte offset when slicing the underlyingString.
§Bounds
A Position is valid for a buffer iff:
row < buffer.lines().len()col <= buffer.line(row).unwrap().chars().count()(one past the last char is allowed — insert mode lives there).
Pass an out-of-bounds Position to crate::Buffer::set_cursor and the
buffer clamps to the nearest valid one via
crate::Buffer::clamp_position. Pass one to
crate::Buffer::apply_edit and the edit is rejected (returns the no-op
inverse).
§Sticky column
crate::Buffer tracks an optional sticky column for j / k motions:
the target column to land in once the cursor reaches a line long enough to
honor it. Never reset it manually outside motion code — it survives
crate::Buffer::set_cursor for that exact reason.
Fields§
§row: usize§col: usizeImplementations§
Trait Implementations§
Source§impl Ord for Position
impl Ord for Position
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Position
impl PartialOrd for Position
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<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
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more