1 个不稳定版本
| 0.1.0 | 2021 年 12 月 26 日 |
|---|
#90 在 #optional
7KB
自主选择
一个微小的过程宏,可以将所有结构体字段设置为可选。目前,这个包基本上是微不足道的,尽管如果你有一些非常大的 struct 需要将所有字段类型从 T 转换为 Option<T>,这可能是有用的。(我需要这个,现在它存在了!)
用法
在您的 Cargo.toml 中添加 discretionary 作为依赖项
[dependencies]
discretionary = "0.1"
然后使用 #[make_optional] 宏装饰您的 struct。就是这样!
例如,以下内容
use discretionary::make_optional;
#[make_optional]
struct ExampleStruct {
id: usize,
name: String,
}
将被重新编写为类似的内容
struct ExampleStruct {
id: Option<usize>,
name: Option<String>,
}
依赖项
~1.5MB
~35K SLoC