pub struct Position {
pub byte_offset: u64,
pub line: u64,
pub column: u64,
}Expand description
A point in a source file.
line and column are 1-based, as an editor reports them. byte_offset is
0-based, as a slice index requires.
Fields§
§byte_offset: u64Offset from the start of the input, in bytes.
Sixty-four bits, because a reader that streams a window at a time is not bounded by what fits in memory and an offset past four gibibytes is ordinary rather than exceptional.
line: u641-based line number.
column: u641-based column number, counted in bytes.
Implementations§
Source§impl Position
impl Position
Sourcepub const fn new(byte_offset: u64, line: u64, column: u64) -> Self
pub const fn new(byte_offset: u64, line: u64, column: u64) -> Self
Creates a position.
§Examples
use molframe_core::Position;
let at = Position::new(42, 3, 7);
assert_eq!(at.line, 3);Sourcepub const fn advance(self, byte: u8) -> Option<Self>
pub const fn advance(self, byte: u8) -> Option<Self>
Advances past one byte, tracking the line and column.
A newline moves to column 1 of the next line; everything else advances the column. Carriage returns advance the column like any other byte, so a CRLF file reports the column of the visible character.
Trait Implementations§
impl Copy for Position
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
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum 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,
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