ParserHelper

Struct ParserHelper 

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

Wraps a slice of input bytes to provide methods for advancing through the input, tracking position, signaling parse errors, looking ahead, etc.

Implementations§

Source§

impl<'a> ParserHelper<'a>

Source

pub fn new(input: &'a [u8]) -> Self

Parses from a slice of bytes.

Source

pub fn len(&self) -> usize

Return the total length of the input.

Source

pub fn slice<I: SliceIndex<[u8]>>(&self, i: I) -> &'a I::Output

Obtain a slice into the original input.

Source

pub fn rest(&self) -> &'a [u8]

Reference to portion of buffer yet to be parsed

Source

pub fn position(&self) -> usize

Current byte offset of buffer being parsed

Source

pub fn fail<T, E>(&self, reason: E) -> Result<T, Error<E>>

Produce an error at the current position.

Source

pub fn fail_at_position<T, E>( &self, reason: E, position: usize, ) -> Result<T, Error<E>>

Produce an error at the given position.

Source

pub fn unexpected_end_of_input<T, E: Eoi>(&self) -> Result<T, Error<E>>

Produce an error indicating the unexpected end of the input at the current position.

Source

pub fn advance(&mut self, offset: usize)

Advance the input slice by some number of bytes.

Source

pub fn advance_over(&mut self, expected: &[u8]) -> bool

Advance the input but only if it matches the given bytes, returns whether it did advance.

Source

pub fn advance_or<E>(&mut self, offset: usize, e: E) -> Result<(), Error<E>>

Advance the input slice by some number of bytes, returning the given error if not enough input is available.

Source

pub fn next<E: Eoi>(&mut self) -> Result<u8, Error<E>>

Consumes the next byte and returns it. Signals unexpected end of the input if no next byte is available.

Source

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

Consumes the next byte and returns it, or signals end of input as None.

Source

pub fn expect<E: Eoi>(&mut self, expected: u8, err: E) -> Result<(), Error<E>>

Consumes the expected byte, gives the given error if it is something else.

Source

pub fn expect_bytes<E>(&mut self, exp: &[u8], err: E) -> Result<(), Error<E>>

Same as expect, but for multiple consecutive bytes.

Source

pub fn expect_pred<E: Eoi>( &mut self, pred: fn(u8) -> bool, err: E, ) -> Result<(), Error<E>>

Same as expect, but using a predicate.

Source

pub fn peek<E: Eoi>(&self) -> Result<u8, Error<E>>

Returns the next byte without consuming it. Signals unexpected end of the input if no next byte is available.

Source

pub fn peek_or_end(&self) -> Option<u8>

Returns the next byte without consuming it, or signals end of input as None.

Source

pub fn skip(&mut self, pred: fn(u8) -> bool)

Skips values while the predicate returns true.

Auto Trait Implementations§

§

impl<'a> Freeze for ParserHelper<'a>

§

impl<'a> RefUnwindSafe for ParserHelper<'a>

§

impl<'a> Send for ParserHelper<'a>

§

impl<'a> Sync for ParserHelper<'a>

§

impl<'a> Unpin for ParserHelper<'a>

§

impl<'a> UnwindSafe for ParserHelper<'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.