Struct Pos

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

A positioned object, functionally equivalent to a struct containing an object of type T (the wrapped object) and its position as a Position<FILE> object.

A parser uses characters inside a text file to create more complex objects. When the parsing fails due to a syntax error you must inform the user about it, in particular you need to tell the user where is the error.

This type associates to a type T (usually a token) a Position that allows the user to locate it inside the file

Implementations§

Source§

impl<T, F> Pos<T, F>

Source

pub const fn new(el: T, pos: Position<F>) -> Self

Creates a new positioned object.

Source

pub const fn new_pos(el: T, file: F, line: u32, column: u32) -> Self

Creates a new positioned object.

Source

pub fn take(self) -> T

Consumes the objects and returns the wrapped element

Source

pub fn take_pos(self) -> Position<F>

Consumes the objects and returns the position

Source

pub fn take_all(self) -> (T, Position<F>)

Consumes the objects and returns both the wrapped element and the position

Source

pub fn test<TF: FnOnce(&T) -> bool>(&self, f: TF) -> bool

Tests the wrapped object

Source

pub fn test_pos<TF: FnOnce(&T, &Position<F>) -> bool>(&self, f: TF) -> bool

Tests both the wrapped object and its position

Source

pub fn map<U, MF: FnOnce(T) -> U>(self, f: MF) -> Pos<U, F>

Apply f at the wrapped object

Source

pub fn map_pos<U, G, MF: FnOnce(T, Position<F>) -> (U, Position<G>)>( self, f: MF, ) -> Pos<U, G>

Apply f at the wrapped object and its position

Source

pub fn make_ref(&self) -> Pos<&T, F>
where F: Clone,

Converts it to a reference

Source

pub fn make_mut(&mut self) -> Pos<&mut T, F>
where F: Clone,

Converts it to a mutable reference

Source§

impl<T, E, F> Pos<Result<T, E>, F>

Source

pub fn from_output(out: Pos<T, F>) -> Self

Build result from output

Source

pub fn from_output_pos(out: T, pos: Position<F>) -> Self

Build result from output and position

Source

pub fn from_residual(out: Pos<Result<Infallible, E>, F>) -> Self

Build result from residual

Source

pub fn from_residual_pos(out: Result<Infallible, E>, pos: Position<F>) -> Self

Build result from residual and position

Source

pub const fn from_err_pos(out: E, pos: Position<F>) -> Self

Build result from error and position

Source

pub fn branch(self) -> ControlFlow<Pos<Result<Infallible, E>, F>, Pos<T, F>>

Branch

Source

pub fn throw(self) -> Result<Pos<T, F>, Pos<E, F>>

Converts a Pos<Result<T, E>, F> into Result<Pos<T, F>, Pos<E, F>> that can be used with the ? operator

Source

pub fn throw_el(self) -> Result<Pos<T, F>, E>

Converts a Pos<Result<T, E>, F> into Result<Pos<T, F>, E> that can be used with the ? operator

Source

pub fn throw_err(self) -> Result<T, Pos<E, F>>

Converts a Pos<Result<T, E>, F> into Result<T, Pos<E, F>> that can be used with the ? operator

Source§

impl<T, F> Pos<Option<T>, F>

Source

pub fn ok_or<E>(self, err: E) -> Result<Pos<T, F>, Pos<E, F>>

Applies Option::ok_or to the wrapped object and then Pos::throw the resulting object

§Errors

If the wrapped value is None then trows passed error

Source

pub fn ok_or_err<E>(self, err: E) -> Result<T, Pos<E, F>>

Applies Option::ok_or to the wrapped object and then Pos::throw_err the resulting object

§Errors

If the wrapped value is None then trows passed error

Source§

impl<B, C, F> Pos<ControlFlow<B, C>, F>

Source

pub fn try_break(self) -> ControlFlow<Pos<B, F>, C>

Converts a Pos<ControlFlow<B, C>, F> into a ControlFlow<Pos<B, F>, C> by moving the resulting Position to the break case

Trait Implementations§

Source§

impl<T, F> AsMut<T> for Pos<T, F>

Source§

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

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T, F> AsRef<T> for Pos<T, F>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone, FILE: Clone> Clone for Pos<T, FILE>

Source§

fn clone(&self) -> Pos<T, FILE>

Returns a copy 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<T: Debug, FILE: Debug> Debug for Pos<T, FILE>

Source§

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

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

impl<T, F> Display for Pos<T, F>
where T: Display, F: Display,

Source§

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

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

impl<T, F> Error for Pos<T, F>
where T: Error, F: Display + Debug,

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl<T, F> Posable<F> for Pos<T, F>

Source§

fn get_pos(&self) -> &Position<F>

Get current position
Source§

fn file(&self) -> &F

Get current file location
Source§

fn line(&self) -> u32

Get line number
Source§

fn column(&self) -> u32

Get column number
Source§

impl<T, F> PosableMut<F> for Pos<T, F>

Source§

fn get_pos_mut(&mut self) -> &mut Position<F>

Get a mutable reference to its position
Source§

fn progress(&mut self, nrow: i32, ncol: i32)

Increase or decrease line and column number by an offset
Source§

impl<T: Copy, FILE: Copy> Copy for Pos<T, FILE>

Auto Trait Implementations§

§

impl<T, FILE> Freeze for Pos<T, FILE>
where T: Freeze, FILE: Freeze,

§

impl<T, FILE> RefUnwindSafe for Pos<T, FILE>
where T: RefUnwindSafe, FILE: RefUnwindSafe,

§

impl<T, FILE> Send for Pos<T, FILE>
where T: Send, FILE: Send,

§

impl<T, FILE> Sync for Pos<T, FILE>
where T: Sync, FILE: Sync,

§

impl<T, FILE> Unpin for Pos<T, FILE>
where T: Unpin, FILE: Unpin,

§

impl<T, FILE> UnwindSafe for Pos<T, FILE>
where T: UnwindSafe, 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.