Skip to content

Save and load configurations effortlessly using a binary configuration file.

License

Notifications You must be signed in to change notification settings

oloko64/binconf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

binconf

Binconf Workflow

Save and load from a binary configuration file with ease.

The data is hashed (XXH3) during serialization and validated when deserializing, so you can be sure that the data is not corrupted.

Crate used for XXH3: xxhash-rust


You can also save the configuration using toml, json, yaml and ron. You need to enable the respective feature for this. (hash validation is not supported for toml, json, yaml or ron)

Optional Features

  • bincode-conf: Enables saving and loading configurations in binary. (Enabled by default)
  • toml-conf: Enables saving and loading configurations using toml.
  • json-conf: Enables saving and loading configurations using json.
  • yaml-conf: Enables saving and loading configurations using yaml.
  • ron-conf: Enables saving and loading configurations using ron.
  • full: Enables all configuration types. This gives you the ability to save and load using toml, json, yaml, ron as well as binary.

Disabling Default Features

If you want to only use one of the features, you can disable the default features and enable the feature you want to use.

Only using toml, for example:

[dependencies.binconf]
features = ["toml-conf"]
default-features = false

Usage

use binconf::ConfigLocation::{Cache, Config, LocalData, Cwd};
use serde::{Deserialize, Serialize};

#[derive(Default, Serialize, Deserialize, Clone)]
struct TestConfig {
    strings: String,
    vecs: Vec<u8>,
}

fn main() {
    let config = TestConfig {
        strings: String::from("binconf"),
        vecs: vec![1, 2, 3, 4, 5],
    };

    // Save the data at the user's config directory
    binconf::store_bin("binconf-app", Some("config.bin"), Config, &config).unwrap();

    // Load the data from the user's config directory
    let stored =
        binconf::load_bin::<TestConfig>("binconf-app", Some("config.bin"), Config, false).unwrap();

    assert_eq!(stored.strings, config.strings);
    assert_eq!(stored.vecs, config.vecs);
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Save and load configurations effortlessly using a binary configuration file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages