cfgmatic
High-level configuration management framework for Rust with derive macros, environment variable support, validation, and Terraform-like plan/apply workflow.
Overview
cfgmatic is a facade crate that re-exports functionality from specialized sub-crates, providing a unified, type-safe API for configuration management:
graph TB
subgraph "cfgmatic (Facade)"
C[cfgmatic]
end
subgraph "Sub-crates"
P[cfgmatic-paths<br/>Path discovery]
F[cfgmatic-files<br/>File loading]
M[cfgmatic-macros<br/>Derive macros]
PL[cfgmatic-plan<br/>Plan/Apply workflow]
end
C --> P
C --> F
C --> M
C --> PL
Crate Overview
| Crate | Purpose | Status |
|---|---|---|
cfgmatic |
Facade - re-exports all crates | Active |
cfgmatic-paths |
Platform-specific path discovery (XDG, Windows, macOS) | Active |
cfgmatic-files |
File discovery, parsing, merging, watching | Active |
cfgmatic-macros |
Derive macros (Config, ConfigEnv) |
Active |
cfgmatic-plan |
Terraform-like plan/apply workflow | Active |
cfgmatic-state |
Legacy state management | Deprecated |
Features
default: Enablesfiles,env, andplanfeaturesfiles: File-based configuration loading (viacfgmatic-files)env: Environment variable support with derive macros (viacfgmatic-macros)plan: Terraform-like plan/apply workflow (viacfgmatic-plan)reactive: Reactive configuration with tokio streams
Installation
[]
= "0.1"
= { = "1", = ["derive"] }
Quick Start
Environment Configuration
use ;
use Deserialize;
Plan/Apply Workflow
Use cfgmatic-plan for Terraform-like state management:
use *;
use ;
// Define a resource
// Implement a handler
;
NPM-style Environment Variables
Environment variables use double underscore (__) as a separator:
# Flat structure
# Nested structure
Using Individual Crates
You can use sub-crates directly for more granular control:
cfgmatic-paths
use PathsBuilder;
let finder = new.build;
let config_path = finder.preferred_config_path;
cfgmatic-files
use ;
let finder = new;
let config = finder.load?;
cfgmatic-plan
use *;
let plan = plan?;
let result = new.execute?;
Migration from cfgmatic-state
cfgmatic-state is deprecated. Migrate to cfgmatic-plan:
// Old (deprecated)
use ;
// New - via cfgmatic facade
use ;
// Or directly
use *;
Feature Flags
| Feature | Description | Default |
|---|---|---|
files |
File-based configuration | Yes |
env |
Environment variable support | Yes |
plan |
Terraform-like plan/apply | Yes |
reactive |
Config subscriptions/watching | No |
Examples
See examples/ directory for complete working examples:
# Environment configuration
# Plan/Apply workflow
# Reactive configuration
License
MIT OR Apache-2.0