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

#87 in Procedural macros

Download history 95911/week @ 2024-12-15 38808/week @ 2024-12-22 48849/week @ 2024-12-29 88329/week @ 2025-01-05 94910/week @ 2025-01-12 90522/week @ 2025-01-19 91520/week @ 2025-01-26 115152/week @ 2025-02-02 105235/week @ 2025-02-09 107034/week @ 2025-02-16 113610/week @ 2025-02-23 118504/week @ 2025-03-02 126316/week @ 2025-03-09 129636/week @ 2025-03-16 125178/week @ 2025-03-23 121394/week @ 2025-03-30

510,175 downloads per month
Used in 470 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

~195–620KB
~15K SLoC