11 releases
0.2.751 | Sep 2, 2024 |
---|---|
0.2.750 | Sep 2, 2024 |
0.2.700 | Jan 6, 2024 |
0.2.630 | Nov 10, 2023 |
0.1.501 | May 27, 2023 |
#106 in Configuration
80KB
2K
SLoC
binconf
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 usingtoml
.json-conf
: Enables saving and loading configurations usingjson
.yaml-conf
: Enables saving and loading configurations usingyaml
.ron-conf
: Enables saving and loading configurations usingron
.full
: Enables all configuration types. This gives you the ability to save and load usingtoml
,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.
Dependencies
~0.4–11MB
~80K SLoC