9 releases

0.3.0 Feb 3, 2024
0.2.0 Mar 21, 2023
0.1.6 Mar 18, 2023
0.1.5 May 5, 2022
0.1.0 Mar 28, 2021

#10 in #parse-attributes

Download history 47161/week @ 2024-03-14 47341/week @ 2024-03-21 39428/week @ 2024-03-28 36552/week @ 2024-04-04 41458/week @ 2024-04-11 39998/week @ 2024-04-18 41229/week @ 2024-04-25 41891/week @ 2024-05-02 45159/week @ 2024-05-09 43001/week @ 2024-05-16 40883/week @ 2024-05-23 43870/week @ 2024-05-30 41350/week @ 2024-06-06 45707/week @ 2024-06-13 53169/week @ 2024-06-20 45480/week @ 2024-06-27

193,642 downloads per month
Used in 292 crates (via structmeta)

MIT/Apache

58KB
1.5K SLoC

StructMeta

Crates.io Docs.rs Actions Status

Parse Rust's attribute arguments by defining a struct.

Documentation

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

Install

Add this to your Cargo.toml:

[dependencies]
structmeta = "0.3.0"
proc-macro2 = "1.0.78"
syn = "2.0.48"
quote = "1.0.35"

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

~265–720KB
~17K SLoC