Expand description
lib-humus-configuration helps with reading a configuration file into a data structure.
It currently supports JSON, JSON5 and TOML.
use serde::Deserialize;
use lib_humus_configuration::read_from_json_file;
#[derive(Deserialize)]
struct TestData {
text: String,
n: i64,
}
let test_data: TestData = read_from_json_file("test-data/test.json").unwrap();
assert_eq!(test_data.text, "Foo Bar".to_string());
assert_eq!(test_data.n, 123);
This is a companion crate to lib-humus.
§Feature Flags
Each format is gated behind its own feature flag, at least one of the has to be enabled.
json
using theserde_json
crate.json5
using thejson5
crate.toml
using thetoml
crate.full
enables all supported formats.
Structs§
- Humus
Config Error - Error type returned when reading a configuration file fails.
- Settings
- Which formats are allowed and which to prefer
Enums§
- Config
Format - Enumerates supported configuration formats.
- Error
Cause - Cause of a HumusConfigError.
Functions§
- read_
from_ file - Read from a given path using the given settings.
- read_
from_ json5_ file - Read from a JSON5 or JSON file at a given path.
- read_
from_ json_ file - Read from a JSON file at a given path.
- read_
from_ toml_ file - Read from a TOML file at a given path.