9个版本
0.3.0 | 2024年2月3日 |
---|---|
0.2.0 | 2023年3月21日 |
0.1.6 | 2023年3月18日 |
0.1.5 | 2022年5月5日 |
0.1.0 | 2021年3月28日 |
#24 在 进程宏 中
193,611 每月下载量
用于 291 个crate(直接使用20个)
57KB
570 行
StructMeta
通过定义结构体解析Rust的属性参数。
文档
有关详细信息,请参阅#[derive(StructMeta)]
文档。
安装
将其添加到您的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());
此代码输出
x = 10, y = abc
许可协议
本项目采用Apache-2.0/MIT双重许可。有关详细信息,请参阅两个LICENSE-*文件。
贡献
除非您明确声明,否则根据Apache-2.0许可协议提交给本项目的工作中的任何贡献,均应如上所述双重许可,不附加任何额外条款或条件。
依赖关系
~280–730KB
~17K SLoC