Struct restq_http::Parser

source ·
pub struct Parser<'a, I, O> {
    pub method: Box<dyn Fn(&'a [I], usize) -> Result<(O, usize), Error> + 'a>,
}
Expand description

Parser combinator.

Fields§

§method: Box<dyn Fn(&'a [I], usize) -> Result<(O, usize), Error> + 'a>

Implementations§

source§

impl<'a, I, O> Parser<'a, I, O>

source

pub fn new<P>(parse: P) -> Parser<'a, I, O>
where P: Fn(&'a [I], usize) -> Result<(O, usize), Error> + 'a,

Create new parser.

source

pub fn parse(&self, input: &'a [I]) -> Result<O, Error>

Apply the parser to parse input.

source

pub fn parse_at( &self, input: &'a [I], start: usize ) -> Result<(O, usize), Error>

Parse input at specified position.

source

pub fn map<U, F>(self, f: F) -> Parser<'a, I, U>
where F: Fn(O) -> U + 'a, I: 'a, O: 'a, U: 'a,

Convert parser result to desired value.

source

pub fn convert<U, E, F>(self, f: F) -> Parser<'a, I, U>
where F: Fn(O) -> Result<U, E> + 'a, E: Debug, O: 'a, U: 'a,

Convert parser result to desired value, fail in case of conversion error.

source

pub fn cache(self) -> Parser<'a, I, O>
where O: Clone + 'a,

Cache parser output result to speed up backtracking.

source

pub fn pos(self) -> Parser<'a, I, usize>
where O: 'a,

Get input position after matching parser.

source

pub fn collect(self) -> Parser<'a, I, &'a [I]>
where O: 'a,

Collect all matched input symbols.

source

pub fn discard(self) -> Parser<'a, I, ()>
where O: 'a,

Discard parser output.

source

pub fn opt(self) -> Parser<'a, I, Option<O>>
where O: 'a,

Make parser optional.

source

pub fn repeat<R>(self, range: R) -> Parser<'a, I, Vec<O>>
where R: RangeArgument<usize> + Debug + 'a, O: 'a,

p.repeat(5) repeat p exactly 5 times p.repeat(0..) repeat p zero or more times p.repeat(1..) repeat p one or more times p.repeat(1..4) match p at least 1 and at most 3 times

source

pub fn name(self, name: &'a str) -> Parser<'a, I, O>
where O: 'a,

Give parser a name to identify parsing errors.

source

pub fn expect(self, name: &'a str) -> Parser<'a, I, O>
where O: 'a,

Mark parser as expected, abort early when failed in ordered choice.

Trait Implementations§

source§

impl<'a, I, O, U> Add<Parser<'a, I, U>> for Parser<'a, I, O>
where O: 'a, U: 'a,

Sequence reserve value

§

type Output = Parser<'a, I, (O, U)>

The resulting type after applying the + operator.
source§

fn add( self, other: Parser<'a, I, U> ) -> <Parser<'a, I, O> as Add<Parser<'a, I, U>>>::Output

Performs the + operation. Read more
source§

impl<'a, Left, Right> Add<Parser<'a, Right>> for Parser<'a, u8, Left>
where Left: 'a, Right: 'a,

Sequence reserve value (but degrade to non-utf8 parser)

§

type Output = Parser<'a, u8, (Left, Right)>

The resulting type after applying the + operator.
source§

fn add( self, other: Parser<'a, Right> ) -> <Parser<'a, u8, Left> as Add<Parser<'a, Right>>>::Output

Performs the + operation. Read more
source§

impl<'a, O> BitOr<Parser<'a, O>> for Parser<'a, u8, O>
where O: 'a,

Ordered choice (but degrade to non-utf8 parser)

§

type Output = Parser<'a, u8, O>

The resulting type after applying the | operator.
source§

fn bitor( self, other: Parser<'a, O> ) -> <Parser<'a, u8, O> as BitOr<Parser<'a, O>>>::Output

Performs the | operation. Read more
source§

impl<'a, I, O> BitOr for Parser<'a, I, O>
where O: 'a,

Ordered choice

§

type Output = Parser<'a, I, O>

The resulting type after applying the | operator.
source§

fn bitor(self, other: Parser<'a, I, O>) -> <Parser<'a, I, O> as BitOr>::Output

Performs the | operation. Read more
source§

impl<'a, O> From<Parser<'a, O>> for Parser<'a, u8, O>

source§

fn from(parser: Parser<'a, O>) -> Parser<'a, u8, O>

Converts to this type from the input type.
source§

impl<'a, I, O, U> Mul<Parser<'a, I, U>> for Parser<'a, I, O>
where I: 'a, O: 'a, U: 'a,

Sequence discard first value

§

type Output = Parser<'a, I, U>

The resulting type after applying the * operator.
source§

fn mul( self, other: Parser<'a, I, U> ) -> <Parser<'a, I, O> as Mul<Parser<'a, I, U>>>::Output

Performs the * operation. Read more
source§

impl<'a, Left, Right> Mul<Parser<'a, Right>> for Parser<'a, u8, Left>
where Left: 'a, Right: 'a,

Sequence discard first value (but degrade to non-utf8 parser)

§

type Output = Parser<'a, u8, Right>

The resulting type after applying the * operator.
source§

fn mul( self, other: Parser<'a, Right> ) -> <Parser<'a, u8, Left> as Mul<Parser<'a, Right>>>::Output

Performs the * operation. Read more
source§

impl<'a, I, O> Neg for Parser<'a, I, O>
where O: 'a,

And predicate

§

type Output = Parser<'a, I, bool>

The resulting type after applying the - operator.
source§

fn neg(self) -> <Parser<'a, I, O> as Neg>::Output

Performs the unary - operation. Read more
source§

impl<'a, I, O> Not for Parser<'a, I, O>
where O: 'a,

Not predicate

§

type Output = Parser<'a, I, bool>

The resulting type after applying the ! operator.
source§

fn not(self) -> <Parser<'a, I, O> as Not>::Output

Performs the unary ! operation. Read more
source§

impl<'a, I, O, U, F> Shr<F> for Parser<'a, I, O>
where O: 'a, U: 'a, F: Fn(O) -> Parser<'a, I, U> + 'a,

Chain two parsers where the second parser depends on the first’s result.

§

type Output = Parser<'a, I, U>

The resulting type after applying the >> operator.
source§

fn shr(self, other: F) -> <Parser<'a, I, O> as Shr<F>>::Output

Performs the >> operation. Read more
source§

impl<'a, I, O, U> Sub<Parser<'a, I, U>> for Parser<'a, I, O>
where O: 'a, U: 'a,

Sequence discard second value

§

type Output = Parser<'a, I, O>

The resulting type after applying the - operator.
source§

fn sub( self, other: Parser<'a, I, U> ) -> <Parser<'a, I, O> as Sub<Parser<'a, I, U>>>::Output

Performs the - operation. Read more
source§

impl<'a, Left, Right> Sub<Parser<'a, Right>> for Parser<'a, u8, Left>
where Left: 'a, Right: 'a,

Sequence discard second value (but degrade to non-utf8 parser)

§

type Output = Parser<'a, u8, Left>

The resulting type after applying the - operator.
source§

fn sub( self, other: Parser<'a, Right> ) -> <Parser<'a, u8, Left> as Sub<Parser<'a, Right>>>::Output

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<'a, I, O> Freeze for Parser<'a, I, O>

§

impl<'a, I, O> !RefUnwindSafe for Parser<'a, I, O>

§

impl<'a, I, O> !Send for Parser<'a, I, O>

§

impl<'a, I, O> !Sync for Parser<'a, I, O>

§

impl<'a, I, O> Unpin for Parser<'a, I, O>

§

impl<'a, I, O> !UnwindSafe for Parser<'a, I, O>

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>,

§

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>,

§

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.