3 个不稳定版本
0.1.2 | 2024年2月3日 |
---|---|
0.1.1 | 2024年2月3日 |
0.0.3 | 2024年2月3日 |
#462 在 #read-write
17KB
259 代码行
包含 (Cab 文件, 14KB) .vs/rust-library/v17/.wsuo
关于
存储允许读取和写入 .io 文件格式 Rust 库代码的仓库。
功能和计划
序列化和反序列化的当前状态
- 原始类型
- 字符串
- 数组
- 向量
- 哈希表
- 结构体(具有命名字段)
- 泛型
- 上述所有功能的组合
- 元组
- 元组结构体
- &str 类型
- 切片
能力
- 使用宏 to_io!() 通过对象引用对 支持类型 进行序列化。
- 使用宏 from_io!() 通过 .io 格式化字符串和所需对象类型对 支持类型 进行反序列化。
- 仅装饰性 支持使用 #[io_name()] 辅助宏在结构体中从和到 .io 格式化字符串重命名字段,使用字符串字面量作为参数。
请参阅下方的 示例 了解这些功能的用法。
示例用法
use io_de_ser::*; // required import
#[derive(IoDeSer, Debug)] // required macro derive IoDeSer, Debug is not required
struct Person<T : IoDeSer> {
#[io_name("Name")] // optional renaming
pub name: String,
#[io_name("LastName")] // optional renaming
pub last_name: String,
#[io_name("Age")] // optional renaming
pub age: u8,
#[io_name("Address")] // optional renaming
pub address: Address<T>,
}
#[derive(IoDeSer, Debug)] // required macro derive, Debug is not required
struct Address<T : IoDeSer> {
pub city: String,
pub number: T,
pub street: String,
}
fn main() {
let person = Person::<u8>{
name: "John".to_string(),
last_name: "Kowalski".to_string(),
age: 21,
address: Address::<u8> {
city: "Warsaw".to_string(),
number: 65,
street: "Tęczowa".to_string(),
},
};
let io_serialization: String = to_io!(&person); // serialization by reference
/* saving to file for example */
println!("{}", &io_serialization);
let person_deserialization : Person<u8> = from_io!(io_serialization, Person<u8>); // deserialization
println!("{:?}", &person_deserialization);
}
/*
Output:
|
Name->|John|
LastName->|Kowalski|
Age->|21|
Address->|
city->|Warsaw|
number->|65|
street->|Tęczowa|
|
|
Person { name: "John", last_name: "Kowalski", age: 21, address: Address { city: "Warsaw", number: 65, street: "Tęczowa" } }
*/
依赖项
~1.5MB
~35K SLoC