Struct TokenCursor

Source
pub struct TokenCursor {
    pub tokens: Vec<Token>,
    pub current_position: usize,
}
Expand description

Cursor for navigating through a vector of tokens

This struct provides methods to access the current token, peek ahead or behind, and advance the cursor position.

§Fields

  • tokens - A vector of tokens to navigate through.
  • current_position - The current position of the cursor within the token vector.

Fields§

§tokens: Vec<Token>§current_position: usize

Implementations§

Source§

impl TokenCursor

Source

pub fn current(&self) -> Option<&Token>

Returns the current token, if any.

Source

pub fn peek_ahead(&self, n: usize) -> Option<&Token>

Returns the nth next token, if any.

§Arguments
  • n - The number of tokens to look ahead.
§Returns

An Option containing a reference to the token if it exists, or None if it is out of bounds.

Source

pub fn _peek_behind(&self, n: usize) -> Option<&Token>

Returns the nth previous token, if any.

§Arguments
  • n - The number of tokens to look behind.
§Returns

An Option containing a reference to the token if it exists, or None if it is out of

Source

pub fn advance(&mut self)

Moves the cursor forward one position.

Source

pub fn _set_position(&mut self, pos: usize)

Sets the cursor’s position to the specified position.

§Arguments
  • pos - The position to set the cursor to.
§Panics

Panics if the position is out of bounds for the token list.

Source

pub fn position(&self) -> usize

Returns the current position of the cursor.

Source

pub fn is_at_eof(&self) -> bool

Returns whether the cursor is at the end of the token list.

Trait Implementations§

Source§

impl Debug for TokenCursor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

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.
§

impl<T> ErasedDestructor for T
where T: 'static,