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>
impl<'a, I, O> Parser<'a, I, O>
sourcepub fn parse_at(
&self,
input: &'a [I],
start: usize
) -> Result<(O, usize), Error>
pub fn parse_at( &self, input: &'a [I], start: usize ) -> Result<(O, usize), Error>
Parse input at specified position.
sourcepub fn map<U, F>(self, f: F) -> Parser<'a, I, U>where
F: Fn(O) -> U + 'a,
I: 'a,
O: 'a,
U: 'a,
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.
sourcepub fn convert<U, E, F>(self, f: F) -> Parser<'a, I, U>
pub fn convert<U, E, F>(self, f: F) -> Parser<'a, I, U>
Convert parser result to desired value, fail in case of conversion error.
sourcepub fn cache(self) -> Parser<'a, I, O>where
O: Clone + 'a,
pub fn cache(self) -> Parser<'a, I, O>where
O: Clone + 'a,
Cache parser output result to speed up backtracking.
sourcepub fn repeat<R>(self, range: R) -> Parser<'a, I, Vec<O>>
pub fn repeat<R>(self, range: R) -> Parser<'a, I, Vec<O>>
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
Trait Implementations§
source§impl<'a, I, O, U> Add<Parser<'a, I, U>> for Parser<'a, I, O>where
O: 'a,
U: 'a,
impl<'a, I, O, U> Add<Parser<'a, I, U>> for Parser<'a, I, O>where
O: 'a,
U: 'a,
Sequence reserve value
source§impl<'a, Left, Right> Add<Parser<'a, Right>> for Parser<'a, u8, Left>where
Left: 'a,
Right: 'a,
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)
source§impl<'a, O> BitOr<Parser<'a, O>> for Parser<'a, u8, O>where
O: 'a,
impl<'a, O> BitOr<Parser<'a, O>> for Parser<'a, u8, O>where
O: 'a,
Ordered choice (but degrade to non-utf8 parser)
source§impl<'a, I, O, U> Mul<Parser<'a, I, U>> for Parser<'a, I, O>where
I: 'a,
O: 'a,
U: 'a,
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
source§impl<'a, Left, Right> Mul<Parser<'a, Right>> for Parser<'a, u8, Left>where
Left: 'a,
Right: 'a,
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)
source§impl<'a, I, O, U, F> Shr<F> for Parser<'a, I, O>
impl<'a, I, O, U, F> Shr<F> for Parser<'a, I, O>
Chain two parsers where the second parser depends on the first’s result.
source§impl<'a, I, O, U> Sub<Parser<'a, I, U>> for Parser<'a, I, O>where
O: 'a,
U: 'a,
impl<'a, I, O, U> Sub<Parser<'a, I, U>> for Parser<'a, I, O>where
O: 'a,
U: 'a,
Sequence discard second value
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more