Struct Cursor

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

Abstraction over a character iterator.

Implementations§

Source§

impl<'a> Cursor<'a>

Source

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

Creates a new Cursor from an input string.

Source

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

Immutable reference to the internal character iterator.

Source

pub fn byte_pos(&self) -> usize

The current byte position of the cursor into the input string.

Source

pub fn peek(&self) -> Option<char>

Peeks the next character without advancing the cursor.

Source

pub fn peek_two(&self) -> (Option<char>, Option<char>)

Peeks the next two characters without advancing the cursor.

Source

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

Bumps the cursor and returns the next character.

Source

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

Bumps the cursor and returns the next two characters.

Source

pub fn skip_while(&mut self, predicate: fn(char) -> bool)

Bumps the cursor while predicate is true for the current character.

Notably, this method will not consume the first non-matching character. This is in contrast with methods like Iterator::take_while. This behavior is achieved by peeking the next character to see if it matches before consuming it.

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