ast_demangle/mini_parser/parsers/
take_while1.rs1use crate::mini_parser::input::{Find, SplitAt};
2use crate::mini_parser::Parser;
3use std::marker::PhantomData;
4
5pub struct TakeWhile1<I, C, F> {
6 f: F,
7 _phantom: PhantomData<fn(I, &mut C)>,
8}
9
10impl<I, C, F> Parser<I, C> for TakeWhile1<I, C, F>
11where
12 I: Find + SplitAt,
13 F: FnMut(I::Item) -> bool,
14{
15 type Output = I::Prefix;
16
17 fn parse(&mut self, input: I, _context: &mut C) -> Result<(Self::Output, I), ()> {
18 let index = input.find(|c| !(self.f)(c));
19
20 if index == 0 {
21 Err(())
22 } else {
23 Ok(input.split_at(index).unwrap())
24 }
25 }
26}
27
28pub fn take_while1<I, C, F>(f: F) -> TakeWhile1<I, C, F>
29where
30 I: Find + SplitAt,
31 F: FnMut(I::Item) -> bool,
32{
33 TakeWhile1 {
34 f,
35 _phantom: PhantomData,
36 }
37}