rust-bakery / nom

Rust parser combinator framework
MIT License
9.18k stars 792 forks source link

Use less specific type in custom combinator example #1662

Closed smheidrich closed 1 year ago

smheidrich commented 1 year ago

The custom combinator from the "Wrapper combinators that eat whitespace before and after a parser" example uses the needlessly specific trait bound FnMut(...) -> IResult for its parser parameter type, which limits its applicability as a combinator, because not all parsers (e.g. Map) implement the FnMut(...) -> IResult trait. But conversely, FnMut(...) -> IResult implements the Parser trait, so IMHO using Parser as the trait bound instead would make perfect sense.

This PR makes that change and also removes a pointless import of nom::combinator::value.

The example in question was the only documentation I could find on how to write a combinator of your own (but to be honest I haven't looked very hard), so that's why I think it's important to get it right.

Geal commented 1 year ago

that part of the doc had not been modified in a while, it's good to update to to use Parser, especially with upcoming changes