#derive #parse #attribute #syn #totokens

structmeta

Parse Rust’s attribute arguments by defining a struct

5 releases

0.1.4 Oct 18, 2021
0.1.3 Apr 7, 2021
0.1.2 Apr 5, 2021
0.1.1 Apr 4, 2021
0.1.0 Mar 28, 2021

#284 in Procedural macros

Download history 561/week @ 2021-08-17 812/week @ 2021-08-24 1105/week @ 2021-08-31 1006/week @ 2021-09-07 1463/week @ 2021-09-14 3441/week @ 2021-09-21 3590/week @ 2021-09-28 2567/week @ 2021-10-05 4504/week @ 2021-10-12 4985/week @ 2021-10-19 3869/week @ 2021-10-26 4386/week @ 2021-11-02 5814/week @ 2021-11-09 6200/week @ 2021-11-16 4982/week @ 2021-11-23 5596/week @ 2021-11-30

23,340 downloads per month
Used in 15 crates (2 directly)

MIT/Apache

96KB
2K SLoC

StructMeta

Crates.io Docs.rs Actions Status

Parse Rust's attribute arguments by defining a struct.

Documentation

See #[derive(StructMeta)] documentation for details.

Example

use structmeta::StructMeta;
use syn::{parse_quote, Attribute, LitInt, LitStr};

#[derive(StructMeta, Debug)]
struct MyAttr {
    x: LitInt,
    y: LitStr,
}
let attr: Attribute = parse_quote!(#[my_attr(x = 10, y = "abc")]);
let attr: MyAttr = attr.parse_args().unwrap();
println!("x = {}, y = {}", attr.x, attr.y.value());

This code outputs:

x = 10, y = abc

License

This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.

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.

Dependencies

~290–710KB
~18K SLoC