5个版本
0.2.3 | 2022年7月7日 |
---|---|
0.2.2 | 2022年6月22日 |
0.2.1 | 2022年6月22日 |
0.2.0 | 2022年6月22日 |
0.1.0 | 2022年6月21日 |
#13 in #procmacro
每月38次下载
在4个crate中(通过empty_type)使用
39KB
852 行
EmptyType Derive宏
用于为EmptyType
实现生成相应的Container
。大致会产生与以下等效的代码:
use empty_type::{EmptyType, Container};
struct Data {
key: String
}
#[derive(Default)]
struct OptionalData {
key: Option<String>
}
impl EmptyType for Data {
type Container = OptionalData;
fn new_container() -> Self::Container {
OptionalData {
key: None
}
}
}
impl Container for OptionalData {
type Value = Data;
fn try_open(&mut self) -> Result<Self::Value, Box<dyn std::error::Error>> {
Ok(Data {
key: self.key.open()
})
}
}
依赖
~1.5MB
~36K SLoC