easy_json_serde

Crates.ioeasy_json_serde
lib.rseasy_json_serde
version0.2.2
sourcesrc
created_at2022-05-19 07:01:44.723521
updated_at2022-05-21 21:17:42.749505
descriptionDead-simple JSON serialization / deserialization
homepage
repositoryhttps://github.com/JosephTLyons/easy_json_serde
max_upload_size
id589549
size40,157
Joseph T. Lyons (JosephTLyons)

documentation

README

easy_json_serde

Dead-simple JSON serialization / deserialization

easy_json_serde works in conjunction with serde. Decorate your structs with serde's Serialize and Deserialize, bring easy_json_serde's EasyJsonSerialize and EasyJsonDeserialize into view, and easily serialize / deserialize to and from JSON.

use std::fs::File;

use easy_json_serde::{EasyJsonDeserialize, EasyJsonSerialize};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct Dog {
    name: String,
    age: u8,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let rufus_original = Dog {
        name: "Rufus".to_string(),
        age: 10,
    };

    let file_name = "dog.json";
    File::save(file_name, &rufus_original, 4)?;

    let mut json_file = File::open(file_name)?;
    let _rufus_deserialized: Dog = Dog::load(&mut json_file)?;

    Ok(())
}
Commit count: 21

cargo fmt