Skip to main content

CaptureCursor

Struct CaptureCursor 

Source
pub struct CaptureCursor<'tokens> { /* private fields */ }
Expand description

A read cursor over one normalized captured-token sequence.

The cursor borrows an already bounded capture and advances only after one requested mechanical shape is present. It knows token structure and no declaration vocabulary beyond an exact word the caller asks it to read.

Implementations§

Source§

impl<'tokens> CaptureCursor<'tokens>

Source

pub fn is_finished(&self) -> bool

Whether this sequence has no token left to read.

Source

pub fn fragment<T>( &mut self, read: impl FnOnce(&mut Self) -> Result<T, CaptureReadRefusal>, ) -> Result<(CapturedFragment<'tokens>, T), CaptureReadRefusal>

Read one caller-defined shape and retain the exact captured run it consumed.

The callback may consume no token where an empty exact Rust seat is lawful. The returned fragment still belongs to this cursor’s original captured sequence and retains its enclosing group boundary.

§Errors

Returns the callback’s exact typed mechanical refusal without advancing past that refusal.

Source

pub fn token( &mut self, ) -> Result<&'tokens CapturedTokenTree, CaptureReadRefusal>

Read any one captured token.

§Errors

Returns a typed missing-token refusal at the current sequence boundary.

Source

pub fn word( &mut self, expected: &str, ) -> Result<&'tokens CapturedTokenTree, CaptureReadRefusal>

Read one exact ordinary word.

A raw identifier does not satisfy this operation because rawness is declaration material. Use CaptureCursor::identifier where either identifier form is lawful.

§Errors

Returns a typed missing or unexpected-token refusal at the exact available span.

Source

pub fn identifier( &mut self, ) -> Result<(&'tokens CapturedTokenTree, &'tokens str), CaptureReadRefusal>

Read one ordinary or raw identifier token.

The returned token retains which form it carried through CapturedTokenTree::word and CapturedTokenTree::raw_identifier.

§Errors

Returns a typed missing or unexpected-token refusal at the exact available span.

Source

pub fn number( &mut self, ) -> Result<(&'tokens CapturedTokenTree, &'tokens str), CaptureReadRefusal>

Read one numeric literal spelling.

§Errors

Returns a typed missing or unexpected-token refusal at the exact available span.

Source

pub fn punctuation( &mut self, mark: char, spacing: CapturedSpacing, ) -> Result<&'tokens CapturedTokenTree, CaptureReadRefusal>

Read one punctuation seat with both character and adjacency stated.

§Errors

Returns a typed missing or unexpected-token refusal at the exact available span.

Source

pub fn thin_arrow( &mut self, ) -> Result<[&'tokens CapturedTokenTree; 2], CaptureReadRefusal>

Read the two punctuation seats of ->.

§Errors

Returns the exact first seat that is missing or disagrees.

Source

pub fn fat_arrow( &mut self, ) -> Result<[&'tokens CapturedTokenTree; 2], CaptureReadRefusal>

Read the two punctuation seats of =>.

§Errors

Returns the exact first seat that is missing or disagrees.

Source

pub fn group( &mut self, delimiter: CapturedDelimiter, ) -> Result<Self, CaptureReadRefusal>

Read one group and open a cursor over its captured members.

A missing token inside the returned cursor points at this group token, which is the exact source boundary the capture retains for an empty or exhausted group.

§Errors

Returns a typed missing or unexpected-token refusal at the exact available span.

Source

pub fn trailing_separated<T, const LIMIT: usize>( self, separator: char, read: impl FnMut(&mut Self) -> Result<T, CaptureReadRefusal>, ) -> Result<Bounded<T, LIMIT>, CaptureReadRefusal>

Read a sequence whose every member is followed by one standalone separator.

Empty standing is deliberately left to the caller: this operation returns an empty Bounded where the sequence is empty. The member reader owns one member’s shape and meaning, while this operation owns cursor progress, the separator seat, and the declared member magnitude.

§Errors

Returns the member reader’s refusal, an exact separator refusal, a nonadvancing-reader refusal, or a refusal at the first member beyond LIMIT.

Source

pub fn finish(self) -> Result<(), CaptureReadRefusal>

Finish this sequence after every token has been consumed.

§Errors

Returns CaptureReadIssue::InputRemaining at the first unconsumed token.

Trait Implementations§

Source§

impl<'tokens> Clone for CaptureCursor<'tokens>

Source§

fn clone(&self) -> CaptureCursor<'tokens>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'tokens> Debug for CaptureCursor<'tokens>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'tokens> Freeze for CaptureCursor<'tokens>

§

impl<'tokens> RefUnwindSafe for CaptureCursor<'tokens>

§

impl<'tokens> Send for CaptureCursor<'tokens>

§

impl<'tokens> Sync for CaptureCursor<'tokens>

§

impl<'tokens> Unpin for CaptureCursor<'tokens>

§

impl<'tokens> UnsafeUnpin for CaptureCursor<'tokens>

§

impl<'tokens> UnwindSafe for CaptureCursor<'tokens>

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.