Simple persistence of Rust structs to disk using Serde.
struct_vault provides small helpers to save/load structs in JSON, YAML, or TOML.
struct_vault is currently not published on crates.io.
[dependencies]
struct_vault = { git = "https://github.com/icsboyx/struct_vault" }use anyhow::Result;
use serde::{Deserialize, Serialize};
use struct_vault::{SaveFormat, load, save};
#[derive(Default, Debug, Serialize, Deserialize)]
struct AppConfig {
name: String,
value: i32,
}
fn main() -> Result<()> {
let cfg = AppConfig {
name: "demo".into(),
value: 42,
};
save(&cfg, "app_config", None, SaveFormat::Toml)?;
let loaded = load::<AppConfig>("app_config", None, SaveFormat::Toml)?;
println!("{loaded:#?}");
Ok(())
}- Default directory is
.config. StructVaultSimpleis available for quick type-based save/load.- You can also use explicit path APIs:
save_to_pathandload_from_path.
examples/01_simple_load.rsexamples/02_simple_save.rsexamples/03_simple_load_or_default.rsexamples/04_simple_struct_vault_simple.rsexamples/05_custom_dir.rsexamples/06_save_in_load_from.rsexamples/05_save_load_fullpath.rs
Run one with:
cargo run --example 05_save_load_fullpathMIT. See LICENSE.