Skip to content

marcdejonge/nom-parse-macros

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nom-parse-macros

CI Crates.io Documentation

This crate provides 2 macros to generate a ParseFrom implementation for a struct or enum using the provided nom expression(s). The expression given should return a tuple for the parsed fields.

There are 2 separate macros available, parse_from and parse_match. The first one is really generic and can be useful in many cases, since you have the full flexibility of nom functions and combinators. The second one is a very simple one that matches a string verbatim. This is useful when you have a very simple format that you want to parse.

As a quick example, consider the following struct:

use nom_parse_macros::parse_from;

#[parse_from((be_32, be_u16))]
struct MyStruct {
    a: u32,
    b: u16,
}

After this, you can easily call MyStruct::parse with a byte array and get a parsed instance back. You have many of the nom functions available to you, so you can parse more complex structures as well. Look at the documentation for more examples and more explanation on how to use the macros.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages