#DuckDuckfedi - if I wanted to store a small state file to disk in my Rust app (tiny), what's the most effecient option these days?
Replying to @arch@floofy.tech
@arch@floofy.tech try nanoserde! its like serde, except, well, not as big.
example (forgive me if i misremembered the api)
use nanoserde::{DeBin, SerBin};
use std::fs;
#[derive(SerBin, DeBin, Debug)]
struct Obesity {
falsity: bool,
name: String,
weight: u8,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let x = Obesity {
name: "Obesity".to_string(),
weight: 5,
falsity: true,
};
fs::write("save.dat", x.serialize_bin())?;
let bytes = fs::read("save.dat")?;
let loaded: Obesity = Obesity::deserialize_bin(&bytes)?;
println!("{:?}", loaded);
Ok(())
}Replying to @stag@mk.absturztau.be
@arch@floofy.tech you can also do .serialize_json()and ::deserialize_json() for plaintext
