Struct minparser::Pos

source ·
pub struct Pos<T, FILE = ()> { /* 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 fn new(el: T, pos: Position<F>) -> Self

Creates a new positioned object. See also Posable::at

source

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

Creates a new positioned object. See also Posable::at_pos

source

pub fn file(&self) -> &F

Get the file identifier

source

pub fn line(&self) -> u32

Get the line number

source

pub fn column(&self) -> u32

Get the column number

source

pub fn mov<G>(self, pos: Position<G>) -> Pos<T, G>

Moves the content to a different position

source

pub fn mov_to<U, G>(self, ot: Pos<U, G>) -> Pos<T, G>

Moves the content to a different position

source

pub fn pos(&self) -> &Position<F>

Gets the position

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<'a>(&'a self) -> Pos<&'a T, F>
where F: Clone,

Converts it to a reference

source

pub fn make_mut<'a>(&'a mut self) -> Pos<&'a 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 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

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

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: 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.