2 releases
Uses new Rust 2024
new 0.1.1 | Mar 31, 2025 |
---|---|
0.1.0 | Mar 31, 2025 |
#196 in #tokio-async
22 downloads per month
Used in 13 crates
(5 directly)
61KB
913 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
SaveToFile
andLoadFromFile
implementations, reducing boilerplate. - Asynchronous Operations: Employs
tokio
to facilitate asynchronous reading from and writing to files, enhancing performance in I/O bound tasks. - Serialize and Deserialize: Leverages
serde
to support the versatile serialization and deserialization of types. - Error Handling: Implements custom error handling using a defined
SaveLoadError
type.
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
~11–23MB
~324K SLoC