binconf

Crates.iobinconf
lib.rsbinconf
version0.2.751
sourcesrc
created_at2023-05-23 22:26:11.323483
updated_at2024-09-02 14:03:43.194389
descriptionSave and load from a binary configuration file with ease.
homepage
repositoryhttps://github.com/OLoKo64/binconf
max_upload_size
id872443
size94,219
Reinaldo Rozato Junior (oloko64)

documentation

README

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


Deprecated Features

The serde_yaml library is currently unmaintained. Although it still functions, I recommend using serde_json or serde_toml as alternatives while a new replacement is being developed.


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.

Commit count: 65

cargo fmt