pub struct ConfigLoader { /* private fields */ }Expand description
Builder for a layered config load.
Sources are applied in the order they were registered. The typical JSS-parity invocation is:
use solid_pod_rs::config::ConfigLoader;
let cfg = ConfigLoader::new()
.with_defaults()
.with_file("config.json")
.with_env()
.load()
.await?;Implementations§
Source§impl ConfigLoader
impl ConfigLoader
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty loader — add sources explicitly. Prefer
Self::with_defaults as the first call so the final snapshot
is always fully populated.
Sourcepub fn with_defaults(self) -> Self
pub fn with_defaults(self) -> Self
Register the hard-coded defaults as the lowest-precedence layer. Idempotent — calling twice has no additional effect.
Sourcepub fn with_file(self, path: impl Into<PathBuf>) -> Self
pub fn with_file(self, path: impl Into<PathBuf>) -> Self
Register a config file source. Format is auto-detected from the
extension: .json (always supported), .yaml/.yml, .toml
(requires the config-loader feature). Missing / malformed
files are a hard error at load time.
Sourcepub fn with_env(self) -> Self
pub fn with_env(self) -> Self
Register the process environment as a source. Reads JSS_*
vars via std::env::var.
Sourcepub fn with_env_overlay(&mut self) -> &mut Self
pub fn with_env_overlay(&mut self) -> &mut Self
Builder alias matching Sprint 11 naming — mutates the loader
in-place and returns &mut Self so operator scripts can chain
overlays without rebinding. Equivalent to Self::with_env on
a mutable loader.
Sourcepub fn with_cli_overlay(&mut self, args: &CliArgs) -> &mut Self
pub fn with_cli_overlay(&mut self, args: &CliArgs) -> &mut Self
Register a CLI args overlay as the highest-precedence layer.
Precedence: Defaults < File < Env < CLI.
The binary crate (clap) is the canonical caller; passing
CliArgs::default() is a no-op overlay (every field None).
Sourcepub fn from_file<P: AsRef<Path>>(
path: P,
) -> impl Future<Output = Result<ServerConfig, PodError>>
pub fn from_file<P: AsRef<Path>>( path: P, ) -> impl Future<Output = Result<ServerConfig, PodError>>
Load a config snapshot directly from a single file path,
bypassing the builder. Format auto-detected from extension. This
is the Sprint 11 row 120 one-shot helper — equivalent to
ConfigLoader::new().with_defaults().with_file(path).load().
Sourcepub async fn load(self) -> Result<ServerConfig, PodError>
pub async fn load(self) -> Result<ServerConfig, PodError>
Resolve all sources in order, merge them, deserialise, and validate.
async for symmetry with JSS’s loadConfig and to leave room
for an eventual remote-config source (e.g. Consul, Vault)
without another breaking change. No await points today.
Sourcepub fn warnings(&self) -> &[String]
pub fn warnings(&self) -> &[String]
Accessor for emitted warnings. Populated as a side-effect of
Self::load if it is called; empty otherwise. Provided so
test code can assert on warning behaviour without relying on a
tracing subscriber.
Trait Implementations§
Source§impl Clone for ConfigLoader
impl Clone for ConfigLoader
Source§fn clone(&self) -> ConfigLoader
fn clone(&self) -> ConfigLoader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more