3 releases
Uses new Rust 2024
| 0.1.2 | Jul 13, 2025 |
|---|---|
| 0.1.1 | Mar 31, 2025 |
| 0.1.0 | Mar 31, 2025 |
#951 in #tokio
1,017 downloads per month
Used in 122 crates
(6 directly)
62KB
911 lines
save-load-derive
save-load-derive is a Rust crate designed to streamline file serialization and deserialization processes for custom types by utilizing procedural macros. It automatically generates implementations for the SaveToFile and LoadFromFile traits using serde for serialization and tokio for asynchronous file operations.
Features
- Automated Code Generation: Utilizes Rust's procedural macros to derive
SaveToFileandLoadFromFileimplementations, reducing boilerplate. - Asynchronous Operations: Employs
tokioto facilitate asynchronous reading from and writing to files, enhancing performance in I/O bound tasks. - Serialize and Deserialize: Leverages
serdeto support the versatile serialization and deserialization of types. - Error Handling: Implements custom error handling using a defined
SaveLoadErrortype.
Usage
To use the save-load-derive crate, apply the SaveLoad derive macro to your structs:
use save_load_derive::SaveLoad;
#[derive(SaveLoad)]
struct MyData {
// your fields here
}
Ensure your type derives or implements serde::Serialize and for<'de> serde::Deserialize<'de> for the macro to succeed without compile errors due to missing trait bounds.
Example
use save_load_derive::SaveLoad;
use serde::{Serialize, Deserialize};
#[derive(SaveLoad, Serialize, Deserialize)]
struct ExampleStruct {
field1: String,
field2: i32,
}
// In asynchronous contexts:
async fn process() -> Result<(), SaveLoadError> {
let data = ExampleStruct {
field1: "data".into(),
field2: 42,
};
data.save_to_file("example.json").await?;
let loaded_data = ExampleStruct::load_from_file("example.json").await?;
Ok(())
}
License
This crate is licensed under the MIT License.
Note: This README was generated by an AI model and may not be 100% accurate, although it aims to be comprehensive and useful.
Dependencies
~14–31MB
~377K SLoC