#settings #save #struct #containing #user #serialization #home

cr_program_settings

A small simple library that allows for saving of a struct containing data for a program to persist

1 unstable release

0.1.2 Aug 11, 2023

#55 in #home

GPL-3.0-only

20KB
226 lines

cr_program_settings

A library that simplifies the process of saving a struct containing the program settings to a file somewhere safe. At the moment, the program allows you to give it a struct, and it will save it in the users home directory with the name of the program using the library. Pretty minimal library that I plan on using for my other projects going forward.

Example usage:
use cr_program_settings::prelude::*;

 // create a struct we want to save, it needs to implement at a minimum of Serialize and Deserialize
 #[derive(Serialize,Deserialize, PartialEq, Debug)]
 struct Settings{
 setting1: u32,
 setting2: String,
 setting3: Vec<bool>,
 }

fn main() {
    let settings = Settings{
        setting1: 128,
        setting2: "this is a cool setting struct".to_string(),
        setting3: vec![false,true,false,false],
    };

    save_settings!(settings).expect("Settings were unable to be saved");

    // -- snip --

    let loaded_settings = load_settings!(Settings).expect("Unable to read settings file");

    assert_eq!(settings,loaded_settings);
}

Dependencies

~0.5–7.5MB
~60K SLoC