1 个不稳定版本
0.1.4 | 2022年5月25日 |
---|---|
0.1.3 |
|
0.1.2 |
|
0.1.1 |
|
0.1.0 |
|
#2844 in Rust 模式
每月 39 次下载
4KB
ToVec
Rust 结构体到切片。
示例一
use struct2vec::ToVec;
use struct2vec_derive::ToVec;
use std::collections::HashMap;
#[derive(ToVec, Debug, Clone, Deserialize, Serialize)]
struct Custom {
#[to_vec(comment = "用户名", field_type = "字段类型")]
name: String,
}
let custom = Custom{name:String::from("123")};
custom.to_vec()
示例二
use struct2vec::ToVec;
use struct2vec_derive::ToVec;
use std::collections::HashMap;
use from_value_derive::From;
#[derive(ToVec, Debug, Clone, Deserialize, Serialize)]
struct Custom {
#[to_vec(comment = "用户名", field_type = "字段类型")]
name: String,
data: Data
}
#[derive(From, Debug, Clone, Deserialize, Serialize)]
struct Data {
key: String
}
let custom = Custom{name:String::from("123")};
custom.to_vec()
依赖项
~1.6–2.3MB
~53K SLoC