Skip to main content

configbuilder_pattern_builder/
config_builder.rs

1use std::path::PathBuf;
2
3/// Assemble application configuration from named sources.
4///
5/// `ConfigBuilder` is a **builder-chain trait** -- it covers only the configuration
6/// fields (`name`, `version`, `with_config_dir`, `with_config_filename`). It
7/// deliberately does **not** include `build_loader()`. That finaliser is an
8/// inherent method on the concrete builder types (see
9/// `configbuilder-svc-saf`) because the construction logic depends
10/// on real filesystem/XDG internals this trait itself must not reference.
11pub trait ConfigBuilder: Sized {
12    /// Return the configured application name.
13    fn name(&self) -> &str;
14
15    /// Return the configured application version.
16    fn version(&self) -> &str;
17
18    /// Set the application name; used by `build_loader` to resolve XDG paths.
19    fn with_name(self, name: impl Into<String>) -> Self;
20
21    /// Set the application version string.
22    fn with_version(self, version: impl Into<String>) -> Self;
23
24    /// Append an explicit config directory; takes precedence over XDG resolution.
25    ///
26    /// Multiple calls accumulate directories -- later entries win on key conflicts.
27    fn with_config_dir(self, dir: impl Into<PathBuf>) -> Self;
28
29    /// Override the config filename searched for in each configured directory.
30    ///
31    /// Defaults to `application.toml` when not called.
32    fn with_config_filename(self, filename: impl Into<String>) -> Self;
33}