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>
impl<T, F> Pos<T, F>
sourcepub fn new(el: T, pos: Position<F>) -> Self
pub fn new(el: T, pos: Position<F>) -> Self
Creates a new positioned object. See also Posable::at
sourcepub fn new_pos(el: T, file: F, line: u32, column: u32) -> Self
pub fn new_pos(el: T, file: F, line: u32, column: u32) -> Self
Creates a new positioned object. See also Posable::at_pos
sourcepub fn mov_to<U, G>(self, ot: Pos<U, G>) -> Pos<T, G>
pub fn mov_to<U, G>(self, ot: Pos<U, G>) -> Pos<T, G>
Moves the content to a different position
sourcepub fn take_all(self) -> (T, Position<F>)
pub fn take_all(self) -> (T, Position<F>)
Consumes the objects and returns both the wrapped element and the position
sourcepub fn test_pos<TF: FnOnce(&T, &Position<F>) -> bool>(&self, f: TF) -> bool
pub fn test_pos<TF: FnOnce(&T, &Position<F>) -> bool>(&self, f: TF) -> bool
Tests both the wrapped object and its position
source§impl<T, E, F> Pos<Result<T, E>, F>
impl<T, E, F> Pos<Result<T, E>, F>
sourcepub fn throw(self) -> Result<Pos<T, F>, Pos<E, F>>
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§impl<T, F> Pos<Option<T>, F>
impl<T, F> Pos<Option<T>, F>
sourcepub fn ok_or<E>(self, err: E) -> Result<Pos<T, F>, Pos<E, F>>
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
sourcepub fn ok_or_err<E>(self, err: E) -> Result<T, Pos<E, F>>
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>
impl<B, C, F> Pos<ControlFlow<B, C>, F>
sourcepub fn try_break(self) -> ControlFlow<Pos<B, F>, C>
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§
impl<T: Copy, FILE: Copy> Copy for Pos<T, FILE>
Auto Trait Implementations§
impl<T, FILE> Freeze for Pos<T, FILE>
impl<T, FILE> RefUnwindSafe for Pos<T, FILE>where
T: RefUnwindSafe,
FILE: RefUnwindSafe,
impl<T, FILE> Send for Pos<T, FILE>
impl<T, FILE> Sync for Pos<T, FILE>
impl<T, FILE> Unpin for Pos<T, FILE>
impl<T, FILE> UnwindSafe for Pos<T, FILE>where
T: UnwindSafe,
FILE: UnwindSafe,
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
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)
clone_to_uninit)