palex::part

Struct InputPart

Source
pub struct InputPart<'a, P: Input> { /* private fields */ }
Expand description

A helper struct for checking if the next token matches your expectations and consuming the token thereupon. Instances of this type can be created with the following methods:

Implementations§

Source§

impl<'a, P: Input> InputPart<'a, P>

Source

pub fn as_str(&self) -> &str

Returns the string slice of the token currently looked at

Source

pub fn is_empty(&self) -> bool

Returns whether the token currently looked at is empty, i.e. has a length of 0

Source

pub fn len(&self) -> usize

Returns the length of the current token in bytes

Source

pub fn take(self, len: usize) -> InputPart<'a, P>

If the token is longer than len bytes, use only the first len bytes of this token. The rest of the string is considered part of the next token.

Source

pub fn take_char(self) -> Option<InputPart<'a, P>>

Ignore everything but the first char of the token. The rest of the string is considered part of the next token.

This returns None if the token is empty.

Source

pub fn take_until(self, c: char) -> InputPart<'a, P>

If the token contains c, use only the part of the token before the first occurrence of c. The rest of the string is considered part of the next token.

Source

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

Consumes and returns the token as string slice.

Trait Implementations§

Source§

impl<'a, P: Input> AsRef<str> for InputPart<'a, P>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.

Auto Trait Implementations§

§

impl<'a, P> Freeze for InputPart<'a, P>

§

impl<'a, P> RefUnwindSafe for InputPart<'a, P>
where P: RefUnwindSafe,

§

impl<'a, P> Send for InputPart<'a, P>
where P: Send,

§

impl<'a, P> Sync for InputPart<'a, P>
where P: Sync,

§

impl<'a, P> Unpin for InputPart<'a, P>

§

impl<'a, P> !UnwindSafe for InputPart<'a, P>

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.