Position

Struct Position 

Source
pub struct Position<FILE = NoFile> { /* private fields */ }
Expand description

A position.

Characters in a text file can be organizes in a virtual grid in order to easily find characters or parsing errors inside the file. Each file can be divided in multiple lines separated by line feed (U+000A) or carriage return + line feed (U+000D + U+000A).

To find a character then you need just the index of the line containing it (the first line has index 0) and the character index inside thai line (also called the column).

Type F is any type that can be used to identify a text file, for example a String, a Path or a custom type that implements at least Clone in order to provide maximum compatibility with other objects in this crate, even it is not strictly required.

If you work on a single file and/or you don’t want to take in account the used file just put NoFile as F.

Implementations§

Source§

impl<F> Position<F>

Source

pub const fn new_file(file: F, line: u32, column: u32) -> Self

Create a new Position at specified file, line and column indices

Source

pub const fn new_file_zero(file: F) -> Self

Create a new Position with line=0 and column=0

Source

pub const fn file(&self) -> &F

Get the file identifier

Source

pub const fn line(&self) -> u32

Get the line number

Source

pub const fn column(&self) -> u32

Get the column number

Source

pub const fn make_ref(&self) -> Position<&F>

Converts it to a reference

Source

pub fn unpack(self) -> (u32, u32, F)

Unpacks the position.

The first integer is the line number, the second one the column number

Source§

impl<F> Position<F>
where F: Default,

Source

pub fn new(line: u32, column: u32) -> Self

Like Position::new_file but with file argument set to F::default()

Source

pub fn new_zero() -> Self

Like Position::new_file_zero but with file argument set to F::default()

Trait Implementations§

Source§

impl<FILE: Clone> Clone for Position<FILE>

Source§

fn clone(&self) -> Position<FILE>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<FILE: Debug> Debug for Position<FILE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F> Display for Position<F>
where F: Display,

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<FILE: PartialEq> PartialEq for Position<FILE>

Source§

fn eq(&self, other: &Position<FILE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<FILE: Copy> Copy for Position<FILE>

Source§

impl<FILE: Eq> Eq for Position<FILE>

Source§

impl<FILE> StructuralPartialEq for Position<FILE>

Auto Trait Implementations§

§

impl<FILE> Freeze for Position<FILE>
where FILE: Freeze,

§

impl<FILE> RefUnwindSafe for Position<FILE>
where FILE: RefUnwindSafe,

§

impl<FILE> Send for Position<FILE>
where FILE: Send,

§

impl<FILE> Sync for Position<FILE>
where FILE: Sync,

§

impl<FILE> Unpin for Position<FILE>
where FILE: Unpin,

§

impl<FILE> UnwindSafe for Position<FILE>
where FILE: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.