pub struct Position {
pub line: u32,
pub column: u32,
pub index: usize,
}Expand description
Represents a position in a text, consisting of line, column, and byte index.
Fields§
§line: u32The current line number (starting from 1).
column: u32The current column number (starting from 1).
index: usizeThe current byte index in the text (starting from 0).
Implementations§
Source§impl Position
impl Position
Sourcepub fn new(line: u32, column: u32, index: usize) -> Self
pub fn new(line: u32, column: u32, index: usize) -> Self
Creates a new Position with the given line, column, and index.
§Arguments
line- The line number (1-based).column- The column number (1-based).index- The byte index in the text (0-based).
§Example
use roan_error::Position;
let pos = Position::new(1, 1, 0);
assert_eq!(pos.line(), 1);
assert_eq!(pos.column(), 1);
assert_eq!(pos.index(), 0);Sourcepub fn increment_line(&mut self)
pub fn increment_line(&mut self)
Increments the line number, resets the column to 1, and increments the index by 1.
Sourcepub fn increment_column(&mut self)
pub fn increment_column(&mut self)
Increments the column number and the index by 1.
Trait Implementations§
Source§impl Ord for Position
impl Ord for Position
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 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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)