Skip to content

Commit e505ab8

Browse files
committed
Add ChoiceParser<Input> for Vec<P> to allow passing vectors to choice
1 parent 16881f1 commit e505ab8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/parser/choice.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,41 @@ array_choice_parser!(
350350
30 31 32
351351
);
352352

353+
#[cfg(feature = "std")]
354+
impl<Input, P> ChoiceParser<Input> for Vec<P>
355+
where
356+
Input: Stream,
357+
P: Parser<Input>,
358+
{
359+
360+
type Output = P::Output;
361+
type PartialState = <[P] as ChoiceParser<Input>>::PartialState;
362+
363+
parse_mode_choice!(Input);
364+
#[inline]
365+
fn parse_mode_choice<M>(
366+
&mut self,
367+
mode: M,
368+
input: &mut Input,
369+
state: &mut Self::PartialState,
370+
) -> ParseResult<Self::Output, <Input as StreamOnce>::Error>
371+
where
372+
M: ParseMode,
373+
{
374+
if mode.is_first() {
375+
self[..].parse_first(input, state)
376+
} else {
377+
self[..].parse_partial(input, state)
378+
}
379+
}
380+
fn add_error_choice(
381+
&mut self,
382+
error: &mut Tracked<<Input as StreamOnce>::Error>
383+
) {
384+
self[..].add_error_choice(error)
385+
}
386+
}
387+
353388
#[derive(Copy, Clone)]
354389
pub struct Choice<P>(P);
355390

0 commit comments

Comments
 (0)