Features
Multi-Format Support
- CONF - Built-in parser for standard .conf files (default)
- INI - Full INI file parsing with sections, comments, and data type detection
- JSON - JSON format with edit capabilities and serialization
- XML - Zero-copy XML parsing with quick-xml for Java/.NET environments
- HCL - HashiCorp Configuration Language for DevOps workflows
- Properties - Complete Java .properties file parsing with Unicode and escaping
- NOML - Advanced configuration with dynamic features (feature:
noml) - TOML - TOML format with format preservation (feature:
toml)
Enterprise Performance
- Sub-50ns Cache Access Target - Multi-tier caching designed for sub-50ns reads on hot paths
- Zero-Copy Parsing - Minimized allocations and string operations where possible
- Lock-Free Read Paths - Poison-resistant locking with graceful failure recovery
- Hot Value Cache - Ultra-fast access for frequently used values
- Cache Hit Ratio Tracking - Built-in performance statistics and monitoring
Note on benchmark numbers: detailed criterion-backed benchmark numbers will land with v1.0.0. Until then, performance claims should be treated as targets, not guarantees.
Production Features
- Configuration Hot Reloading - File watching with thread-safe Arc swapping
- Audit Logging System - Structured event logging with multiple sinks and severity filtering
- Environment Variable Overrides - Smart caching with prefix matching and type conversion
- Schema Validation - Trait-based validation system with feature gates
- Format Preservation - Maintains comments, whitespace, and original formatting
- Async Native - Full async/await support throughout the API
Reliability & Safety
- Zero Unsafe Code - All
unwrap()calls eliminated, comprehensive error handling - Type Safety - Rich type system with automatic conversions and validation
- Enterprise Error Handling - Production-ready error messages with context preservation
- Comprehensive Testing - Extensive unit, integration, and doc test coverage
Why Choose config-lib?
Unified Multi-Format Support
Unlike single-format libraries, config-lib provides seamless access to 8 configuration formats through one consistent API. No need to learn different libraries for TOML, JSON, XML, and HCL - one API handles them all with automatic format detection.
Enterprise-Grade Performance
Multi-tier caching with lock-free read paths is designed to deliver sub-50ns cached access on hot paths. Built for high-throughput applications with minimal performance overhead.
Production-Ready Reliability
Zero unsafe code, comprehensive error handling, and poison-resistant locking ensure your configuration system won't crash your application. Extensive testing coverage validates edge cases and error conditions.
Developer Experience First
Rich type system with automatic conversions, format preservation for round-trip editing, and detailed error messages with source location context. No more cryptic parsing errors or manual type casting.
Advanced Enterprise Features
Hot reloading without service interruption, structured audit logging for compliance, environment variable overrides with smart caching, and schema validation with custom rules - features typically requiring multiple libraries.
Installation
Add to your Cargo.toml:
[]
= "0.9"
# For enhanced functionality, enable optional features:
= { = "0.9", = [
"json", # JSON format support with serialization
"xml", # XML format support with quick-xml backend
"hcl", # HashiCorp Configuration Language support
"toml", # TOML format support with preservation
"noml", # NOML format support with dynamic features
"validation", # Schema validation and type checking
"async", # Async operations and hot reloading
"env-override", # Environment variable override system
"audit", # Audit logging and compliance features
] }
Feature Recommendations:
- Minimal: Use default features for CONF/INI/Properties support
- Web Applications: Add
"json","env-override","validation" - DevOps Tools: Add
"hcl","toml","async","audit" - Enterprise Systems: Add
"xml","validation","audit","env-override" - Full Featured: Include all features for maximum flexibility
Quick Start
use Config;
// Parse any supported format automatically
let mut config = from_string?;
// Access values with type safety
let host = config.get?.as_string?;
let port = config.get?.as_integer?;
let debug = config.get?.as_bool?;
// Modify configuration (preserves format and comments)
config.set?;
config.set?;
println!;
Multi-Format Support
use Config;
// All 8 formats now fully operational
let config = from_string?;
// Consistent API patterns across all parsers
let port = config.get?.as_integer?;
let timeout = config.get
.and_then
.unwrap_or;
let name = config.get
.and_then
.unwrap_or_else;
// Check existence
if config.contains_key
Read-only mode and forward-compatible options
ConfigOptions is the structured place to express the small set of
behaviors that should not be enabled by default — making a Config
read-only, sizing the cache (v0.9.5), etc. The struct is
#[non_exhaustive] so v0.9.x can add new knobs without breaking
SemVer; callers go through the consuming builder methods.
use ;
// Default options — caching on, writes allowed.
let _cfg = with_options;
// Read-only configuration for a hot path that must never be mutated.
let opts = new.read_only;
let mut locked = with_options;
assert!; // rejected
Deprecated in v0.9.4.
EnterpriseConfigand the multi-tiercache_stats()/make_read_only()API are deprecated as of v0.9.4. They continue to compile and work through the v0.9.x line and the v1.x deprecation window, but new code should useConfig+ConfigOptionsdirectly. The lock-free caching that madeEnterpriseConfigdistinct lands on the unifiedConfigin v0.9.5. See.dev/ROADMAP.mdfor the full timeline andexamples/enterprise_demo.rsfor a side-by-side migration table.
Default Configuration Settings
config-lib provides multiple powerful methods for setting default/preset values that serve as fallbacks when keys are missing from configuration files. This ensures your application always has sensible defaults while allowing configuration files to override specific values.
Method 1: ConfigBuilder with Presets (Recommended)
use ;
use HashMap;
// Set up comprehensive default values before loading config files
let mut defaults = new;
defaults.insert;
defaults.insert;
defaults.insert;
// Server defaults
defaults.insert;
defaults.insert;
defaults.insert;
defaults.insert;
// Database defaults
defaults.insert;
defaults.insert;
defaults.insert;
defaults.insert;
// Logging defaults
defaults.insert;
defaults.insert;
defaults.insert;
// Create config with defaults, then load from file
let config = new
.with_defaults // Apply presets first
.from_file? // File values override presets
.build?;
// All values are guaranteed to exist (from file or defaults)
let app_name = config.get?.as_string?; // File value or "MyApplication"
let port = config.get?.as_integer?; // File value or 8080
let pool_size = config.get?.as_integer?; // File value or 10
let log_level = config.get?.as_string?; // File value or "info"
Method 2: Inline defaults at the access site
The simplest pattern when defaults are only needed at the call site —
no parallel defaults table to maintain, no unwrap on a key that may
not exist.
use Config;
let config = from_file?;
let environment = config
.get
.and_then
.map
.unwrap_or_else;
let cache_ttl: i64 = config
.get
.and_then
.unwrap_or;
let workers: i64 = config
.get
.and_then
.unwrap_or;
Migrated from
EnterpriseConfig::set_default/get_or_default(deprecated v0.9.4). The richer separate-defaults-table API returns in v0.9.5 onceConfigOptionsgains adefaultsfield alongside the caching layer. Seeexamples/enterprise_demo.rsfor the side-by-side migration table.
Method 3: Inline Defaults with get_or()
use Config;
// Load configuration file
let config = from_file?;
// Provide defaults inline when accessing values
let app_config = AppConfig ;
Best Practices for Default Configuration
- Use Sensible Defaults: Choose defaults that work for most use cases
- Document Defaults: Keep defaults in sync with documentation
- Environment-Specific: Use different defaults for dev/staging/production
- Type Safety: Ensure defaults match expected types
- Validation: Validate both defaults and overrides
- Performance: Use Enterprise config for high-performance scenarios
// Example: Production-ready defaults with validation
use ;
// Production defaults (secure and performant)
let defaults = from;
// Validation rules for all values (including defaults)
let validator = new
.add_rule
.add_rule
.add_rule;
let config = new
.with_defaults
.from_file?
.with_validation // Validate defaults + file values
.build?;
Environment Variable Integration
use ;
// Load configuration with environment variable overrides
let mut config = from_file?;
// Enable environment variable overrides with prefix
let env_override = new
.with_prefix // Maps MYAPP_DATABASE_HOST to database.host
.with_separator // Use underscore as path separator
.case_insensitive; // MYAPP_database_HOST also works
config.apply_env_overrides?;
// Now environment variables override file values:
// MYAPP_DATABASE_HOST=prod.db.com overrides database.host from file
// MYAPP_SERVER_PORT=9090 overrides server.port from file
let host = config.get?.as_string?; // From env or file
let port = config.get?.as_integer?; // From env or file
Configuration Validation & Type Safety
use ;
// Define validation rules for configuration
let validator = new
.add_rule
.add_rule
.add_rule
.add_rule;
let mut config = from_file?;
// Validate configuration before use
validator.validate?; // Fails fast with detailed error messages
// Safe access with automatic type conversion
let port = config.get?.as_integer?; // Guaranteed valid range
let log_level = config.get?.as_string?; // Guaranteed valid value
Hot Reloading & Audit Logging
use ;
// Enable audit logging
let audit_logger = new
.with_console_sink
.with_file_sink?;
// Hot reloading configuration
let config = from_file_with_hot_reload?;
Advanced Multi-File Configuration
use ;
// Load and merge multiple configuration files
let config = new
.from_file? // Base configuration
.merge_file? // Environment overrides
.merge_file? // Local additions
.merge_file? // Secure values
.build?;
// Access merged configuration
let database_url = config.get?.as_string?; // From secrets.hcl
let app_name = config.get?.as_string?; // From default.conf
let debug_mode = config.get?.as_bool?; // From environment.json
Status: Late Beta — On the Path to v1.0.0
Current Version: 0.9.x — late beta, API stabilizing, structurally mature.
Target: 1.0.0 stable, scheduled per the roadmap in .dev/ROADMAP.md.
What's complete:
- Universal Format Support - All 8 configuration formats with consistent API (CONF, INI, JSON, XML, HCL, Properties, NOML, TOML)
- Multi-Tier Caching - Designed for sub-50ns cached reads on hot paths
- Production Safety - Zero unsafe code, comprehensive error handling, poison-resistant locking
- Advanced Features - Hot reloading, audit logging, environment overrides, schema validation
- Developer Experience - Rich type system, format preservation (NOML/TOML), automatic type conversion
- Quality Assurance - Comprehensive test suite, zero clippy warnings
What's planned for v1.0.0:
- Unified
ConfigAPI (consolidation underway —EnterpriseConfigdeprecated in v0.9.4, data-model merger lands with caching in v0.9.5) - Lock-free cached reads with verified sub-50ns benchmarks
- Event-driven hot reload via
notify(inotify / FSEvents / ReadDirectoryChangesW) - Fuzz-tested parsers for every format
- Stability contract: API frozen for the lifetime of v1.x
Performance targets (to be verified by committed benchmarks before v1.0.0):
- <50ns cached value access on hot paths
- <500ns cached write
- <100ms hot-reload detection latency (event-driven)
- Zero-allocation hot-path reads
Note on API stability: The public API is not yet frozen. Expect refinements through 0.9.x releases. The v1.0.0 release will lock down the stability contract documented in docs/STABILITY-1.0.md.
Documentation & Resources
Documentation
- Documentation Index - Complete documentation hub and navigation
- API Reference - Comprehensive API documentation with examples
- Valid Formats - Detailed format specifications and examples
- Code Guidelines - Development standards and best practices
External Resources
- API Documentation - Complete API reference with examples
- Crate Registry - Official crate distribution
- Examples Directory - 20+ comprehensive examples covering all features
- Performance Benchmarks - Detailed performance analysis and comparisons
- NOML Language - NOML language specification and usage.
Getting Started Guides
- Quick Start Guide - Basic configuration loading and access
- Multi-Format Demo - Working with different configuration formats
- Enterprise Features - Advanced caching and performance
- Hot Reloading - Dynamic configuration updates
- Validation System - Schema validation and type checking
Common Use Cases
- Web Applications: Environment overrides, JSON/TOML configs
- DevOps Tools: HCL integration, audit logging, hot reloading
- Enterprise Systems: XML support, validation, caching
- Microservices: Multi-format support, environment-based configuration
Troubleshooting
Version Compatibility
- Rust: 1.82+ (currently); MSRV will be lowered to 1.75 in
v1.0.0per portfolio standard - Edition: 2021 (currently); will move to 2024 in
v1.0.0 - MSRV Policy: Once
v1.0.0ships, MSRV is guaranteed within the last 12 stable Rust releases - API Stability: Pre-1.0 — expect refinements.
v1.0.0will freeze the public API. - Feature Flags: All optional features maintain independent compatibility
Development Setup
Contributing
We welcome contributions! See our Contributing Guide for details.