config_get/lib.rs
1//! # config-get
2//!
3//! Cross-platform configuration file locator and reader for Rust.
4//!
5//! `config-get` automatically discovers and reads configuration files from
6//! standard OS-specific locations, supporting `.env`, `.ini`, `.toml`, `.json`,
7//! `.yml`, and `.yaml` formats — no manual path wrangling required.
8//!
9//! ## Quick start
10//!
11//! ```rust
12//! # use config_get::ConfigGet;
13//! # fn main() -> config_get::Result<()> {
14//! # /*
15//! let cfg = ConfigGet::builder("myapp")
16//! .config_dir("myapp")
17//! .build()?;
18//!
19//! let host = cfg.get("DB_HOST").unwrap_or("localhost");
20//! let port: u16 = cfg.parse("DB_PORT")?;
21//! let debug = cfg.get_in_or("server", "debug", "false");
22//! # */
23//! # Ok(())
24//! # }
25//! ```
26//!
27//! ## Features
28//!
29//! | Feature | Enables | Default |
30//! |---------|---------|---------|
31//! | `dotenv` | `.env` via `dotenvy` | ✓ |
32//! | `ini` | `.ini` via `rust-ini` | ✓ |
33//! | `toml` | `.toml` via `toml` | ✓ |
34//! | `yaml` | `.yaml`/`.yml` via `serde_yaml` | ✓ |
35//! | `cli` | `config-get` binary via `clap` | ✗ |
36//! | `all` | All of the above | ✗ |
37
38#![cfg_attr(docsrs, feature(doc_cfg))]
39#![forbid(unsafe_code)]
40#![warn(
41 missing_docs,
42 clippy::pedantic,
43 clippy::unwrap_used,
44 clippy::expect_used
45)]
46#![allow(clippy::module_name_repetitions)]
47
48/// Core [`ConfigGet`] type and its builder.
49pub mod config_get;
50
51/// Platform-aware directory search logic.
52pub mod discovery;
53
54/// Error types for this crate.
55pub mod error;
56
57/// Supported file format detection.
58pub mod format;
59
60/// Format-specific parsers.
61pub mod parsers;
62
63/// Internal key/value storage.
64pub mod value;
65
66// Top-level re-exports for ergonomic use.
67pub use config_get::ConfigGet;
68pub use config_get::ConfigGetBuilder;
69pub use error::{ConfigError, Result};
70pub use format::Format;
71pub use value::ConfigMap;
72
73/// Convenience function — returns the path of the first matching config file,
74/// or `None`.
75///
76/// ```rust
77/// use config_get::get_config_file;
78/// let path = get_config_file("myapp", "myapp");
79/// // path.is_some() if a config file was found
80/// ```
81#[must_use]
82pub fn get_config_file(stem: &str, config_dir: &str) -> Option<std::path::PathBuf> {
83 ConfigGet::search_paths(stem, config_dir)
84 .into_iter()
85 .find(|p| p.is_file())
86}