SourceCursor

Struct SourceCursor 

Source
pub struct SourceCursor<'s, S: Source + ?Sized> { /* private fields */ }
Expand description

A cursor over a source that allows for efficient navigation and scanning.

Implementations§

Source§

impl<'s, S: Source + ?Sized> SourceCursor<'s, S>

Source

pub fn new(source: &'s S) -> Self

Creates a new SourceCursor at the start of the source.

Source

pub fn new_at(source: &'s S, offset: usize) -> Self

Creates a new SourceCursor at the specified offset.

Source

pub fn position(&self) -> usize

Returns the current byte offset of the cursor.

Source

pub fn set_position(&mut self, offset: usize) -> usize

Sets the current byte offset of the cursor. Returns the previous offset.

Source

pub fn source(&self) -> &'s S

Returns the source that this cursor is iterating over.

Source

pub fn rest(&mut self) -> &str

Returns the remaining text in the current chunk.

Source

pub fn chunk_end(&mut self) -> usize

Returns the end byte offset of the current chunk.

Source

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

Peeks at the next character without advancing the cursor.

Source

pub fn skip_ascii_whitespace(&mut self) -> Range<usize>

Skips common ASCII whitespace using SIMD if possible.

Source

pub fn skip_ascii_digits(&mut self) -> Range<usize>

Skips ASCII digits using SIMD if possible.

Source

pub fn skip_ascii_ident_continue(&mut self) -> Range<usize>

Skips ASCII identifier continue characters using SIMD if possible.

Source

pub fn skip_until(&mut self, target: u8) -> Range<usize>

Skips until the specified byte is found.

Source

pub fn peek_byte(&mut self) -> Option<u8>

Peeks at the next byte without advancing. the cursor.

Source

pub fn advance_bytes(&mut self, len: usize) -> usize

Advances the cursor by the specified number of bytes.

Source

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

Advances the cursor by one character and returns it.

Source

pub fn advance_byte(&mut self) -> Option<u8>

Advances the cursor by one byte and returns it.

Source

pub fn take_while(&mut self, pred: impl FnMut(char) -> bool) -> Range<usize>

Advances the cursor while the predicate is true and returns the range.

Source

pub fn take_while_byte(&mut self, pred: impl FnMut(u8) -> bool) -> Range<usize>

Advances the cursor while the byte predicate is true and returns the range.

Source

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

Returns true if the source text at the current position starts with the given pattern.

Source

pub fn consume_if_starts_with(&mut self, pattern: &str) -> bool

Consumes the given pattern if it matches at the current position.

Source

pub fn find_str(&mut self, pattern: &str) -> Option<usize>

Finds the first occurrence of the given pattern in the source text starting from the current position.

Trait Implementations§

Source§

impl<'s, S: Source + ?Sized> Debug for SourceCursor<'s, S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'s, S> Freeze for SourceCursor<'s, S>
where S: ?Sized,

§

impl<'s, S> RefUnwindSafe for SourceCursor<'s, S>
where S: RefUnwindSafe + ?Sized,

§

impl<'s, S> Send for SourceCursor<'s, S>
where S: ?Sized,

§

impl<'s, S> Sync for SourceCursor<'s, S>
where S: ?Sized,

§

impl<'s, S> Unpin for SourceCursor<'s, S>
where S: ?Sized,

§

impl<'s, S> UnwindSafe for SourceCursor<'s, S>
where S: RefUnwindSafe + ?Sized,

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.