pf_config
Crate: pf_config · Path: crates/config/pf_config
Description (Cargo.toml): Layered configuration loader (JSON, env, dotenv, Cargo.toml section) with optional WASM-friendly path later
Layered configuration loader that merges multiple sources in precedence order (low → high): Cargo.toml section (optional) → JSON files → .env (optional) → OS environment variables. Target-agnostic by design; initial implementation is native-only.
Feature flags
Section titled “Feature flags”From crates/config/pf_config/Cargo.toml:
| Feature | Purpose |
|---|---|
default | (empty — no features enabled by default) |
dotenv | .env file loading via dotenvy |
cargo-toml | Cargo.toml [package.metadata.*] section parsing via toml |
Public API (from src/lib.rs)
Section titled “Public API (from src/lib.rs)”load_config::<T>(opts)— load and deserialize config into a typed structT: DeserializeOwnedload_config_untyped(opts)— load config as a rawserde_json::ValueLoadOptions— configuration for the loader:json_paths: Vec<PathBuf>— JSON files to load (default:./config.json)enable_dotenv: bool— whether to load.env(default:true)env_prefix: Option<&'static str>— filter env vars by prefix (default:"AGENT_")env_key_transform: EnvKeyTransform— how to map env keys to nested JSONrequired: bool— error if no sources found (default:false)cargo: Option<CargoTomlOptions>— Cargo.toml table path (feature:cargo-toml)
EnvKeyTransform— enum:DoubleUnderscoreToNested(convertsPREFIX_A__B__Cto nested{"a":{"b":{"c": value}}})CargoTomlOptions—path: PathBuf,table_path: Vec<&'static str>(feature:cargo-toml)ConfigError— error enum:Io,JsonParse,TomlParse(feature:cargo-toml),TypeMismatch,NotFound
Example sketch
Section titled “Example sketch”use pf_config::{load_config, LoadOptions};use serde::Deserialize;
#[derive(Deserialize)]struct AgentCfg { name: String, port: u16,}
let opts = LoadOptions { json_paths: vec!["./agent.json".into()], env_prefix: Some("AGENT_"), ..Default::default()};let cfg: AgentCfg = load_config(opts)?;Full API reference: cargo doc -p pf_config --no-deps --all-features