Skip to main content

Cursor

Struct Cursor 

Source
pub(crate) struct Cursor<'a, T: EncodingType> {
    pos: usize,
    source: &'a [T::CodeUnit],
}
Expand description

Cursor is a small cursor implementation for parsing Iso8601 grammar.

Fields§

§pos: usize§source: &'a [T::CodeUnit]

Implementations§

Source§

impl<'a, T: EncodingType> Cursor<'a, T>

Source

pub fn new(source: &'a [T::CodeUnit]) -> Self

Create a new cursor from a source UTF8 string.

Source

pub(crate) fn slice( &self, start: usize, end: usize, ) -> Option<&'a [T::CodeUnit]>

Returns a string value from a slice of the cursor.

Source

pub(crate) const fn pos(&self) -> usize

Get current position

Source

pub(crate) fn set_position(&mut self, pos: usize)

Get current position

Source

pub(crate) fn peek(&self) -> ParserResult<Option<u8>>

Peek the value at next position (current + 1).

Source

pub(crate) fn current(&self) -> ParserResult<Option<u8>>

Returns current position in source as char.

Source

pub(crate) fn peek_n(&self, n: usize) -> ParserResult<Option<u8>>

Peeks the value at n as a char.

Source

pub(crate) fn check<F>(&self, f: F) -> ParserResult<Option<bool>>
where F: FnOnce(u8) -> bool,

Runs the provided check on the current position.

Source

pub(crate) fn check_or<F>(&self, default: bool, f: F) -> ParserResult<bool>
where F: FnOnce(u8) -> bool,

Runs the provided check on current position returns the default value if None.

Source

pub(crate) fn next(&mut self) -> ParserResult<Option<u8>>

Returns Cursor’s current char and advances to the next position.

Source

pub(crate) fn next_digit(&mut self) -> ParserResult<Option<u8>>

Returns the next value as a digit

§Errors
Source

pub(crate) fn next_or(&mut self, err: ParseError) -> ParserResult<u8>

A utility next method that returns an ParseError::AbruptEnd error if invalid.

Source

pub(crate) fn advance_n(&mut self, n: usize)

Advances the cursor’s position by n code points.

Source

pub(crate) fn advance(&mut self)

Source

pub(crate) fn advance_if(&mut self, condition: bool)

Utility function to advance when a condition is true

Source

pub(crate) fn close(&mut self) -> ParserResult<()>

Closes the current cursor by checking if all contents have been consumed. If not, returns an error for invalid syntax.

Trait Implementations§

Source§

impl<'a, T: Debug + EncodingType> Debug for Cursor<'a, T>
where T::CodeUnit: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

impl<'a, T> Send for Cursor<'a, T>
where <T as EncodingType>::CodeUnit: Sync,

§

impl<'a, T> Sync for Cursor<'a, T>
where <T as EncodingType>::CodeUnit: Sync,

§

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

§

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

§

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

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.