lib_humus_configuration/
lib.rs

1// SPDX-FileCopyrightText: 2025 Slatian
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5//! lib-humus-configuration helps with reading a configuration file into a data structure.
6//!
7//! It currently supports JSON, JSON5 and TOML.
8//!
9//! ```rust
10//! use serde::Deserialize;
11//! use lib_humus_configuration::read_from_json_file;
12//!
13//! #[derive(Deserialize)]
14//! struct TestData {
15//! 	text: String,
16//! 	n: i64,
17//! }
18//!
19//! let test_data: TestData = read_from_json_file("test-data/test.json").unwrap();
20//!
21//! assert_eq!(test_data.text, "Foo Bar".to_string());
22//! assert_eq!(test_data.n, 123);
23//! ```
24//!
25//! This is a companion crate to [lib-humus](https://docs.rs/lib-humus).
26//!
27//! ## Feature Flags
28//!
29//! Each format is gated behind its own feature flag, at least one of the has to be enabled.
30//!
31//! * `json` using the `serde_json` crate.
32//! * `json5` using the `json5` crate.
33//! * `toml` using the `toml` crate.
34//! * `full` enables all supported formats.
35//! 
36
37#![warn(missing_docs)]
38#![allow(clippy::tabs_in_doc_comments)]
39
40mod error;
41mod format;
42mod io;
43mod settings;
44
45#[cfg(test)]
46mod test;
47
48pub use error::ErrorCause;
49pub use error::HumusConfigError;
50pub use format::ConfigFormat;
51pub use io::read_from_file;
52pub use settings::Settings;
53
54#[cfg(feature="json")]
55pub use io::read_from_json_file;
56#[cfg(feature="json5")]
57pub use io::read_from_json5_file;
58#[cfg(feature="toml")]
59pub use io::read_from_toml_file;
60
61#[cfg(not(any(feature="json", feature="json5", feature="toml")))]
62compile_error!("Please enable at least one of the format features on the lib-humus-configuration crate: json, json5 or toml");