hotswap_config/lib.rs
1//! # hotswap-config
2//!
3//! Zero-downtime configuration management with lock-free hot-reloads and atomic updates.
4//!
5//! ## Overview
6//!
7//! `hotswap-config` provides a production-ready configuration library that combines:
8//! - Lock-free atomic reads using `arc-swap`
9//! - Zero-downtime hot-reloads with validation
10//! - Standard configuration precedence (files → env vars)
11//! - Optional advanced features (partial updates, rollback, gradual rollout)
12//!
13//! ## Quick Start
14//!
15//! ```rust,no_run
16//! use hotswap_config::prelude::*;
17//! use serde::Deserialize;
18//!
19//! #[derive(Debug, Deserialize, Clone)]
20//! struct AppConfig {
21//! server: ServerConfig,
22//! database: DatabaseConfig,
23//! }
24//!
25//! #[derive(Debug, Deserialize, Clone)]
26//! struct ServerConfig {
27//! port: u16,
28//! }
29//!
30//! #[derive(Debug, Deserialize, Clone)]
31//! struct DatabaseConfig {
32//! url: String,
33//! }
34//!
35//! # async fn example() -> hotswap_config::error::Result<()> {
36//! // Load configuration with standard precedence
37//! let config = HotswapConfig::builder()
38//! .with_file("config/default.yaml")
39//! .with_env_overrides("APP", "__")
40//! .build::<AppConfig>()
41//! .await?;
42//!
43//! // Zero-cost reads (no locks!)
44//! let cfg = config.get();
45//! println!("Server port: {}", cfg.server.port);
46//! # Ok(())
47//! # }
48//! ```
49//!
50//! ## Features
51//!
52//! - **Lock-free reads**: Sub-10ns read latency using `arc-swap`
53//! - **Atomic updates**: Readers never see partial state
54//! - **File watching**: Automatic reload on file changes
55//! - **Validation**: Reject invalid configs, keep old one
56//! - **Partial updates**: JSON Patch for surgical changes
57//! - **Rollback**: Time-travel to previous configs
58//! - **Gradual rollout**: A/B test configuration changes
59//! - **Remote sources**: HTTP, etcd, Consul support
60//! - **Secret management**: Vault, AWS, GCP integration
61//!
62//! ## Feature Flags
63//!
64//! Enable optional features in your `Cargo.toml`:
65//!
66//! ```toml
67//! [dependencies]
68//! hotswap-config = { version = "0.1", features = ["partial-updates", "rollback"] }
69//! ```
70//!
71//! See the [crate documentation](https://docs.rs/hotswap-config) for all available features.
72
73#![warn(missing_docs, rust_2024_compatibility)]
74#![deny(unsafe_code)]
75
76pub mod core;
77pub mod error;
78pub mod sources;
79
80#[cfg(feature = "partial-updates")]
81pub mod features;
82
83#[cfg(feature = "file-watch")]
84pub mod notify;
85
86#[cfg(feature = "metrics")]
87pub mod metrics;
88
89/// Convenient re-exports for common usage patterns.
90pub mod prelude {
91 pub use crate::core::{HotswapConfig, HotswapConfigBuilder};
92 pub use crate::error::{ConfigError, Result, ValidationError};
93
94 #[cfg(feature = "validation")]
95 pub use crate::core::Validate;
96}