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

#55 in Procedural macros

Download history 73132/week @ 2024-10-11 78104/week @ 2024-10-18 84178/week @ 2024-10-25 84284/week @ 2024-11-01 79412/week @ 2024-11-08 78688/week @ 2024-11-15 82339/week @ 2024-11-22 91305/week @ 2024-11-29 94520/week @ 2024-12-06 99980/week @ 2024-12-13 47296/week @ 2024-12-20 44704/week @ 2024-12-27 82179/week @ 2025-01-03 95346/week @ 2025-01-10 88506/week @ 2025-01-17 78794/week @ 2025-01-24

355,306 downloads per month
Used in 421 crates (20 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

~225–670KB
~16K SLoC