talira

config-rs

Layered configuration for Rust applications, from files, the environment and defaults

open sourceMIT OR Apache-2.0free

config-rs (the config crate) is a layered configuration system for Rust applications, with strong support for 12-factor apps. You set defaults, layer files in JSON, TOML, YAML, INI, RON, JSON5 or Corn and environment variables on top, override values in code, and read the result in any type there's a reasonable conversion to. Nested fields are reached with a path (redis.port, databases[0].name), each file format is a Cargo feature, and a Format trait adds custom formats. It reads configuration only: it can't write changed values back to files.

Problems it solves

  • load settings from a TOML file and override them with environment variables in Rust
  • merge default, file and environment configuration for a 12-factor Rust service
  • read nested configuration values by path in a Rust app

Features

  • layered defaults, files, environment variables and overrides
  • JSON, TOML, YAML, INI, RON, JSON5 and Corn files, each behind a Cargo feature
  • loosely typed reads with conversions
  • nested field paths such as databases[0].name
  • Format trait for custom formats

Limitations

  • It can't write changed configuration values back to the configuration files.1