#derive #parse #attribute #syn #totokens

structmeta

Parse Rust's attribute arguments by defining a struct

8 releases

new 0.2.0 Mar 21, 2023
0.1.6 Mar 18, 2023
0.1.5 May 5, 2022
0.1.4 Oct 18, 2021
0.1.0 Mar 28, 2021

#53 in Procedural macros

Download history 10925/week @ 2022-11-29 10544/week @ 2022-12-06 11072/week @ 2022-12-13 10103/week @ 2022-12-20 5768/week @ 2022-12-27 8699/week @ 2023-01-03 10745/week @ 2023-01-10 10271/week @ 2023-01-17 11957/week @ 2023-01-24 11693/week @ 2023-01-31 11175/week @ 2023-02-07 12343/week @ 2023-02-14 12791/week @ 2023-02-21 11396/week @ 2023-02-28 12687/week @ 2023-03-07 12096/week @ 2023-03-14

51,460 downloads per month
Used in 95 crates (7 directly)

MIT/Apache

55KB
562 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.2.0"
syn = "2.0.4"

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

~0.7–1MB
~26K SLoC