configulator/options.rs
1use std::path::PathBuf;
2
3#[cfg(feature = "file")]
4use crate::file::FileLoader;
5
6/// Options for loading configuration from a file.
7///
8/// Users must supply a [`FileLoader`] implementation that knows how to
9/// parse the file contents.
10/// Use [`serde_loader`](crate::serde_loader) for any serde-compatible format.
11#[cfg(feature = "file")]
12pub struct FileOptions {
13 /// List of file paths to search. The first one found is used.
14 pub paths: Vec<PathBuf>,
15 /// If true, return an error if no config file is found.
16 pub error_if_not_found: bool,
17 /// The loader that parses file contents into configuration values.
18 pub loader: Box<dyn FileLoader>,
19}
20
21#[cfg(feature = "file")]
22impl std::fmt::Debug for FileOptions {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 f.debug_struct("FileOptions")
25 .field("paths", &self.paths)
26 .field("error_if_not_found", &self.error_if_not_found)
27 .field("loader", &"<dyn FileLoader>")
28 .finish()
29 }
30}
31
32/// Options for loading configuration from environment variables.
33#[cfg(feature = "env")]
34#[derive(Debug, Clone)]
35pub struct EnvironmentVariableOptions {
36 /// Prefix for env vars (e.g. `"APP"` with separator `"__"` → `APP__PORT`).
37 pub prefix: String,
38 /// Separator between prefix and field names (e.g. `"__"` → `APP__DATABASE__HOST`).
39 pub separator: String,
40}
41
42/// Options for loading configuration from CLI flags.
43#[cfg(feature = "cli")]
44#[derive(Debug, Clone)]
45pub struct CLIFlagOptions {
46 /// Separator for nested struct fields in flag names (e.g. `"."` → `--database.host`).
47 pub separator: String,
48}