Crates.io | cr_program_settings |
lib.rs | cr_program_settings |
version | 0.1.2 |
source | src |
created_at | 2023-08-11 03:47:48.295029 |
updated_at | 2023-08-11 03:47:48.295029 |
description | A small simple library that allows for saving of a struct containing data for a program to persist |
homepage | https://github.com/CoryRobertson/cr_program_settings |
repository | https://github.com/CoryRobertson/cr_program_settings |
max_upload_size | |
id | 941548 |
size | 64,963 |
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.
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);
}