Native Rust port of go.jtlabs.io/settings.
This workspace provides a layered configuration crate that composes settings from:
- base file (
yaml/json) - defaults map
- CLI-provided override files
- env-provided override files
- CLI arguments
- environment variables
Later sources override earlier sources.
- CI workflow:
/.github/workflows/ci.yml - Coverage badge is powered by Codecov.
- Every CI run uploads coverage artifacts:
coverage-html(download and openindex.html)coverage-lcov(lcov.info)
- CI uploads
lcov.infoto Codecov for tracked percentage coverage. - Pushes to
mainpublish HTML coverage to GitHub Pages.- Expected URL:
https://jtlabsio.github.io/rust-settings/ - If your repo owner/name differs, update this URL accordingly.
- If the repository is private, add
CODECOV_TOKENin GitHub repo secrets.
- Expected URL:
crates/settings: runtime API (gather,ReadOptions, errors)crates/settings-derive:#[derive(SettingsSchema)]and#[settings(...)]metadata attributes
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use settings::{gather, options, SettingsSchema};
#[derive(Debug, Deserialize, Serialize, SettingsSchema)]
struct Config {
#[settings(arg = "--name", env = "APP_NAME")]
name: String,
#[settings(arg = "--created", env = "APP_CREATED")]
created: DateTime<Utc>,
}
let mut cfg = Config {
name: "default".into(),
created: DateTime::parse_from_rfc3339("2020-01-01T00:00:00.000Z")
.unwrap()
.with_timezone(&Utc),
};
let opts = options()
.with_base_path("./defaults.yaml")
.with_default("name", "fallback")
.with_env_override(vec!["GO_ENV"])
.with_env_search_paths(vec!["./", "./config"])
.with_env_search_pattern("config.%s");
gather(opts, &mut cfg)?;
# Ok::<(), settings::SettingsError>(())- Attribute mappings are ergonomic defaults; explicit maps in
ReadOptionsoverride derive-provided mappings. - Runtime injection helpers (
with_runtime_args,with_runtime_env) are available for deterministic testing.