-
I want to write a custom combinator that is not generic over the input and output type but I'm having a lot of trouble writing the output type. What I wanted to do: fn example_combinator(prefix: &'static str) -> impl Parser<_, _, _> // What types go here?
{
(prefix, take_while(0.., '_')).recognize()
} As a work around I can do this: fn example_combinator2<'s>(prefix: &'static str) -> impl Fn(&mut &'s str) -> PResult<&'s str> {
move |input| (prefix, take_while(0.., '_')).recognize().parse_next(input)
} |
Beta Was this translation helpful? Give feedback.
Answered by
epage
Jan 4, 2024
Replies: 2 comments
-
fn example_combinator(prefix: &'static str) -> impl Parser<&str, &str, ContextError>` // What types go here?
{
(prefix, take_while(0.., '_')).recognize()
} With
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
basro
-
Thanks for your answer and this great library! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With
Parser<I, O, E>
I
maps to the input to yourFn
O
maps to the first (or only) parameter forPResult
E
maps to the second parameter toPResult
which is defaulted to beContextError