prefstore
A rust crate to Easily store and retrieve preferences in rust.
Installation
Install the crate as a dependency in your app's Cargo.toml file:
[]
= "0.1.0"
Usage
Import prefstore:
use *;
Save value to disk.
savepreference;
APPNAME: folder name to store to on disk in the config folder.
KEY: the name of the preference/config, filename to store to in APPNAME dir.
VALUE: the preference/config value to store, stored in the KEY.txt file in APPNAME dir. Tested using bool,i32,f64,etc.
Load value from disk.
getpreference;
APPNAME: folder name on disk to load from in the config folder.
KEY: the name of the preference/config, filename to load from in APPNAME dir.
DEFAULT_VALUE: the default preference/config value to return, if the KEY doesn't exist on disk. Tested using bool,i32,f64,etc.
The saved configs are stored at location as defined by dirs crate's config_dir:
Linux: /home/$USERNAME/.config/APPNAME
Win: Drivename:\Users\$USERNAME\AppData\Roaming\APPNAME
Mac: /Users/$USERNAME/Library/Application Support\APPNAME
Delete preference/config file from disk:
clearpreference;
APPNAME: folder name to delete from on disk in the config folder.
KEY: the name of the preference/config file to delete, filename to delete in APPNAME dir.
The VALUE can be any value that implements ToString trait from rustlib. Note as per doc: This trait is automatically implemented for any type which implements the [Display] trait. As such, ToString shouldn't be implemented directly: [Display] should be implemented instead, and you get the ToString implementation for free.