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

#39 in Procedural macros

Download history 75529/week @ 2024-08-13 66957/week @ 2024-08-20 76073/week @ 2024-08-27 84323/week @ 2024-09-03 71711/week @ 2024-09-10 65362/week @ 2024-09-17 78946/week @ 2024-09-24 77862/week @ 2024-10-01 71553/week @ 2024-10-08 75556/week @ 2024-10-15 80569/week @ 2024-10-22 87082/week @ 2024-10-29 78913/week @ 2024-11-05 78992/week @ 2024-11-12 85007/week @ 2024-11-19 63191/week @ 2024-11-26

321,245 downloads per month
Used in 390 crates (21 directly)

MIT/Apache

57KB
570 lines

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

~250–700KB
~17K SLoC