pub struct Position {
pub line: u32,
pub byte: u32,
}Expand description
A logical cursor position: zero-based line, zero-based byte offset within that line. UTF-8 byte offsets, not codepoint indices.
Ordering is lexicographic — by line, then byte — so < means “earlier in
the buffer”. Nothing here validates a position against a buffer: a byte
past the end of the line, or inside a multi-byte character, is
representable, and it is the consumer’s job to clamp or reject it
(ProtocolError::PositionOutOfBounds).
§Examples
use lattice_protocol::Position;
// "héllo": `é` is two UTF-8 bytes, so the `l` after it is at byte 3.
let l = Position::new(0, 3);
assert!(Position::ZERO < l);
assert!(Position::new(0, 99) < Position::new(1, 0)); // line winsFields§
§line: u32Zero-based line index.
byte: u32Zero-based UTF-8 byte offset from the start of line (tree-sitter’s
Point.column convention). A value equal to the line’s byte length is
the end-of-line position.
Implementations§
Trait Implementations§
impl Copy for Position
Source§impl<'de> Deserialize<'de> for Position
impl<'de> Deserialize<'de> for Position
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Position
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 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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.