5个版本
0.1.4 | 2024年5月26日 |
---|---|
0.1.3 | 2024年5月26日 |
0.1.2 | 2024年5月26日 |
0.1.1 | 2024年5月26日 |
0.1.0 | 2024年5月26日 |
#542 in 过程宏
每月 40 次下载
16KB
159 行
Deserter
一组用于使用JavaScript-like语法初始化结构体的两个过程宏。换句话说,通过编译时检查将数据反序列化到结构体值。
用法
可以在可以加载的结构体上添加 #[loadable]
属性,并可以使用 load!
宏来初始化一个可加载的结构体。所有本身是结构体的字段也必须标记为 #[loadable]
use deserter::{load, loadable};
#[loadable]
struct ZipCode {
digits: u32,
}
#[loadable]
struct Address {
house: u32,
street: &'static str,
city: &'static str,
zip_code: ZipCode,
}
#[loadable]
struct Person {
name: &'static str,
age: u32,
address: Address,
}
fn example() {
let john = load!(
Person {
name = "john",
age = 30,
address = {
house = 101,
street = "Main Street",
city = "New York",
zip_code = {
digits = 100200
}
}
}
);
// do things with john, it is a `Person`.
}
依赖
~320–790KB
~18K SLoC