Crate nom_parse_trait

Source
Expand description

#nom-parse-trait

This is an extension to the popular nom crate, that provides a ParseFrom trait that can be implemented on any data that can be parsed in a singular way. This means it should have a parse function available and the signature of that function is compatible with the nom::Parser trait.

The main usage of this is to easily combine parsers of different types. To see the real power of this trait, take a look at he nom-parse-macros trait, which makes it possible easily implement this trait on data types.

§Generic vs Specific parsers

The ParseFrom trait is generic over the input type, which means that you can define it generically over any input type that nom supports. The downside of this is that you will need a bunch of restrictions to the input type in a where block. Also, using a generic parser implementation can be more annoying to use, since in some cases Rust can’t infer the type of the input or error. See the generic_input example for an example of this.

If you already know what types of input and error you are going to use in the program, using a specific implementation can be more convenient. See the simple example for an example of this.

Traits§

ParseFrom
A trait for types that can be parsed from the given input.
ParseFromExt
An extension for the ParseFrom trait with extra functionality to make parse a bit easier.