Skip to main content

Module config

Module config 

Source
Available on crate feature config only.
Expand description

Configuration management with 8-layer cascade.

Provides a hierarchical configuration system matching hyperi-pylib (Python) and hyperi-golib (Go). Configuration is loaded from multiple sources with clear priority ordering.

§Cascade Priority (highest to lowest)

  1. CLI arguments (via clap integration)
  2. Environment variables (with configurable prefix)
  3. .env file (loaded via dotenvy)
  4. PostgreSQL (optional, via config-postgres feature)
  5. settings.{env}.yaml (environment-specific)
  6. settings.yaml (base settings)
  7. defaults.yaml
  8. Hard-coded defaults

§How .env Files Work in the Cascade

dotenvy::dotenv() loads .env into the process environment, so .env values are read at layer 2 alongside real env vars. Real env vars win: dotenvy does NOT overwrite existing variables.

§Environment Variable Naming

Use the env_compat module for standardised environment variable names with legacy alias support and deprecation warnings.

§Example

use hyperi_rustlib::config::{self, ConfigOptions};

// Initialise with env prefix
config::setup(ConfigOptions {
    env_prefix: "MYAPP".into(),
    ..Default::default()
}).unwrap();

// Access configuration
let cfg = config::get();
let host = cfg.get_string("database.host").unwrap_or_default();
let port = cfg.get_int("database.port").unwrap_or(5432);

Modules§

env_compat
Environment variable compatibility layer.
flat_env
Flat environment variable override helpers.
registry
Reflectable configuration registry.
reloaderconfig-reload
Universal configuration reloader for DFE components.
sensitive
Re-exports SensitiveString from the crate root for backward compatibility.
sharedconfig-reload
Generic thread-safe shared configuration with version tracking.

Structs§

Config
Configuration manager wrapping Figment.
ConfigOptions
Configuration options.

Enums§

ConfigError
Configuration errors.

Functions§

get
Get the global configuration.
setup
Initialise the global configuration.
try_get
Try to get the global configuration.