hjkl_config/lib.rs
1//! Shared TOML config loader for hjkl-based apps.
2//!
3//! Apps implement [`AppConfig`] on their config struct and call [`load`]
4//! to read it from the platform's XDG config directory. Missing files
5//! return `Default::default()` paired with [`ConfigSource::Defaults`] —
6//! no file is ever auto-created.
7//!
8//! ```no_run
9//! use hjkl_config::{AppConfig, load};
10//! use serde::Deserialize;
11//!
12//! #[derive(Debug, Default, Deserialize)]
13//! struct MyConfig {
14//! greeting: String,
15//! }
16//!
17//! impl AppConfig for MyConfig {
18//! const APPLICATION: &'static str = "myapp";
19//! }
20//!
21//! let (cfg, source) = load::<MyConfig>().unwrap();
22//! ```
23
24mod error;
25mod loader;
26mod validate;
27mod write;
28
29pub use error::ConfigError;
30pub use loader::{
31 AppConfig, ConfigSource, cache_dir, config_dir, config_path, data_dir, load, load_from,
32 load_layered, load_layered_from,
33};
34pub use validate::{
35 Validate, ValidationError, ensure_non_empty_str, ensure_non_zero, ensure_one_of, ensure_range,
36};
37pub use write::write_key_at;