oni_comb_parser_rs/internal/parser_impl/
parser_monad_impl.rs

1use crate::core::{Element, Parser, ParserFilter, ParserMonad, Parsers};
2use crate::internal::ParsersImpl;
3
4impl<'a, I, A> ParserFilter<'a> for Parser<'a, I, A> {
5  fn with_filter<F>(self, f: F) -> Self::P<'a, Self::Input, Self::Output>
6  where
7    F: Fn(&Self::Output) -> bool + 'a,
8    Self::Input: Element,
9    Self::Output: Clone + 'a, {
10    ParsersImpl::filter(self, move |e| f(e))
11  }
12}
13
14impl<'a, I, A> ParserMonad<'a> for Parser<'a, I, A> {
15  fn flat_map<B, F>(self, f: F) -> Self::P<'a, Self::Input, B>
16  where
17    F: Fn(Self::Output) -> Self::P<'a, Self::Input, B> + 'a,
18    Self::Input: 'a,
19    Self::Output: 'a,
20    B: 'a, {
21    ParsersImpl::flat_map(self, move |e| f(e))
22  }
23}