cfgmatic-source
Unified configuration source abstraction for the cfgmatic framework.
Overview
cfgmatic-source provides a trait-based abstraction for loading configuration
from various sources. It follows hexagonal architecture principles with clear
separation between domain, application, and infrastructure layers.
Features
- FileSource - Load configuration from files (TOML, JSON, YAML)
- EnvSource - Load from environment variables with prefix support
- MemorySource - In-memory source for testing
- CompositeSource - Combine multiple sources with priorities
- Async Support - Optional async API via
asyncfeature flag - Format Detection - Automatic format detection from file extensions
Installation
Add to your Cargo.toml:
[]
= "2.1"
Feature Flags
| Feature | Description | Default |
|---|---|---|
file |
File source support | Yes |
env |
Environment source | Yes |
toml |
TOML format support | Yes |
json |
JSON format support | Yes |
yaml |
YAML format support | No |
async |
Async API support | No |
Quick Start
File Source
use *;
// Single file
let source = new;
let content = source.load_raw?;
// Multiple files (merged)
let source = builder
.path
.path
.required
.build?;
let parsed = source.load?;
Environment Source
use *;
// With prefix
let source = with_prefix;
// Reads MYAPP_DATABASE_URL, MYAPP_SERVER_PORT, etc.
let content = source.load_raw?;
Composite Source
use *;
let composite = builder
.add
.add
.build?;
let config = composite.load?;
Using with Loader
use *;
use Deserialize;
let source = new;
let loader = new;
let config: Config = loader.load_as?;
Architecture
+-------------------------------------------------+
| lib.rs |
| (Facade + Re-exports) |
+-------------------------------------------------+
|
+-------------------------------------------------+
| Config Layer |
| LoadOptions, SourceConfig |
+-------------------------------------------------+
|
+-------------------------------------------------+
| Application Layer |
| Loader, SourceCoordinator |
+-------------------------------------------------+
|
+-------------------------------------------------+
| Infrastructure Layer |
| FileSource, EnvSource, MemorySource, etc. |
+-------------------------------------------------+
|
+-------------------------------------------------+
| Domain Layer |
| Source trait, Format, RawContent, Errors |
+-------------------------------------------------+
API Reference
See the API documentation for full details.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.