Skip to main content

Cursor

Struct Cursor 

Source
pub struct Cursor<'a> { /* private fields */ }
Expand description

A Cursor over a string.

Based on rustc’s Cursor

Implementations§

Source§

impl<'a> Cursor<'a>

Source

pub fn new(source: &'a str) -> Self

Source

pub fn offset(&self) -> TextSize

Retrieves the current offset of the cursor within the source code.

Source

pub fn chars(&self) -> Chars<'a>

Return the remaining input as a string slice.

Source

pub fn as_bytes(&self) -> &'a [u8]

Returns the remaining input as byte slice.

Source

pub fn as_str(&self) -> &'a str

Returns the remaining input as string slice.

Source

pub fn first(&self) -> char

Peeks the next character from the input stream without consuming it. Returns EOF_CHAR if the file is at the end of the file.

Source

pub fn second(&self) -> char

Peeks the second character from the input stream without consuming it. Returns EOF_CHAR if the position is past the end of the file.

Source

pub fn last(&self) -> char

Peeks the next character from the input stream without consuming it. Returns EOF_CHAR if the file is at the end of the file.

Source

pub fn text_len(&self) -> TextSize

Source

pub fn token_len(&self) -> TextSize

Source

pub fn start_token(&mut self)

Source

pub fn is_eof(&self) -> bool

Returns true if the file is at the end of the file.

Source

pub fn bump(&mut self) -> Option<char>

Consumes the next character

Source

pub fn bump_back(&mut self) -> Option<char>

Consumes the next character from the back

Source

pub fn eat_char(&mut self, c: char) -> bool

Source

pub fn eat_char2(&mut self, c1: char, c2: char) -> bool

Eats the next two characters if they are c1 and c2. Does not consume any input otherwise, even if the first character matches.

Source

pub fn eat_char3(&mut self, c1: char, c2: char, c3: char) -> bool

Eats the next three characters if they are c1, c2 and c3 Does not consume any input otherwise, even if the first character matches.

Source

pub fn eat_char_back(&mut self, c: char) -> bool

Source

pub fn eat_if(&mut self, predicate: impl FnMut(char) -> bool) -> bool

Eats the next character if predicate returns true.

Source

pub fn eat_while(&mut self, predicate: impl FnMut(char) -> bool)

Eats symbols while predicate returns true or until the end of file is reached.

Source

pub fn eat_back_while(&mut self, predicate: impl FnMut(char) -> bool)

Eats symbols from the back while predicate returns true or until the beginning of file is reached.

Source

pub fn skip_bytes(&mut self, count: usize)

Skips the next count bytes.

§Panics
  • If count is larger than the remaining bytes in the input stream.
  • If count indexes into a multi-byte character.

Trait Implementations§

Source§

impl<'a> Clone for Cursor<'a>

Source§

fn clone(&self) -> Cursor<'a>

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<'a> Debug for Cursor<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Cursor<'a>

§

impl<'a> RefUnwindSafe for Cursor<'a>

§

impl<'a> Send for Cursor<'a>

§

impl<'a> Sync for Cursor<'a>

§

impl<'a> Unpin for Cursor<'a>

§

impl<'a> UnsafeUnpin for Cursor<'a>

§

impl<'a> UnwindSafe for Cursor<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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.