An ergonomic [Parser] for #[attributes], built on parser combinators.
let mut rename_all = None::;
let mut untagged = false;
let mut deny_unknown_fields = false;
let mut path_to_serde: Path = parse_quote!;
let attrs: = parse_quote! ;
new
.once
.once
.once
.once
.parse_attrs?;
assert_eq!;
assert!;
assert!; // not encountered, so not set
assert_eq!;
Guide
#[attributes] as they are used in the Rust compiler
and in the wild tend to look like this:
// ^^^^ ^^^^^ ^^^ ^
// path key (val) bare key
// ^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^ ^^^^^^^^
// path key = val bare key
To use this library, create an [Attrs],
and register different keys, each with a parsing function.
This library provides many parsing functions, but there are four key kinds:
littakes a literal liketrueor100from the input.from_strtakes a".."string from the input, before trying to [FromStr] it into an object.parse_strtakes a".."string from the input, before trying to [syn::parse] it into an object.parsedirectly tries to [syn::parse] the input.
Every function takes an &mut reference to its destination,
which will be filled in when the corresponding key is encountered.
The [on] module acts on direct references,
whereas the [set] module acts on [Option]s, filling them with [Some].
The main ways to separate a key from its value are provided as combinators in the [with] module:
- [
with::eq] take an=from the input. - [
with::paren] take a group(..)from the input.
You may choose to accept a key once or many times,
and you can, of course, write your own parsing functions for whatever syntax you have in mind.