Skip to main content

Cursor

Struct Cursor 

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

A position in some text, and the bash word grammar over it.

Built by parse_with, which is also what checks that a grammar consumed the whole input.

Implementations§

Source§

impl<'a> Cursor<'a>

Source

pub fn at(&self) -> usize

The byte offset reached so far.

Source

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

What has not been read yet.

Source

pub fn at_end(&self) -> bool

Source

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

Source

pub fn starts_with(&self, text: &str) -> bool

Source

pub fn fail(&self, message: impl Into<String>) -> ParseError

A refusal at the current position, carrying the text around it.

Source

pub fn eat(&mut self, text: &str) -> bool

Consume text if it is next, and say whether it was.

Source

pub fn lit(&mut self, text: &str) -> Result<(), ParseError>

Consume text, which must be next.

Source

pub fn take_while(&mut self, accept: impl Fn(char) -> bool) -> &'a str

Every leading character the predicate accepts, possibly none.

Source

pub fn ws0(&mut self)

Spaces, tabs and newlines, possibly none.

Source

pub fn word(&mut self, stops: &[char]) -> Result<String, ParseError>

One word: a first segment, then every adjacent one that still belongs to it. The first must be there; a following one that will not read ends the word rather than failing 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> 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> 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.