#derive #parse #attribute #syn #totokens

structmeta

Parse Rust's attribute arguments by defining a struct

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

#20 in Procedural macros

Download history 30855/week @ 2023-11-01 29477/week @ 2023-11-08 31590/week @ 2023-11-15 28564/week @ 2023-11-22 30350/week @ 2023-11-29 30615/week @ 2023-12-06 27011/week @ 2023-12-13 20697/week @ 2023-12-20 17690/week @ 2023-12-27 27670/week @ 2024-01-03 28691/week @ 2024-01-10 31342/week @ 2024-01-17 32246/week @ 2024-01-24 41885/week @ 2024-01-31 35021/week @ 2024-02-07 30684/week @ 2024-02-14

145,620 downloads per month
Used in 222 crates (15 directly)

MIT/Apache

57KB
571 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

~335–790KB
~19K SLoC