Crates.io | structmeta-derive |
lib.rs | structmeta-derive |
version | 0.3.0 |
source | src |
created_at | 2021-03-28 06:42:45.792218 |
updated_at | 2024-02-03 11:16:37.520341 |
description | derive macro for structmeta crate. |
homepage | |
repository | https://github.com/frozenlib/structmeta |
max_upload_size | |
id | 374553 |
size | 57,682 |
Parse Rust's attribute arguments by defining a struct.
See #[derive(StructMeta)]
documentation for details.
Add this to your Cargo.toml:
[dependencies]
structmeta = "0.3.0"
proc-macro2 = "1.0.78"
syn = "2.0.48"
quote = "1.0.35"
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
This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.
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.