Crate lib_humus_configuration

Source
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 the serde_json crate.
  • json5 using the json5 crate.
  • toml using the toml crate.
  • full enables all supported formats.

Structs§

HumusConfigError
Error type returned when reading a configuration file fails.
Settings
Which formats are allowed and which to prefer

Enums§

ConfigFormat
Enumerates supported configuration formats.
ErrorCause
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.