Crate hotswap_config

Crate hotswap_config 

Source
Expand description

§hotswap-config

Zero-downtime configuration management with lock-free hot-reloads and atomic updates.

§Overview

hotswap-config provides a production-ready configuration library that combines:

  • Lock-free atomic reads using arc-swap
  • Zero-downtime hot-reloads with validation
  • Standard configuration precedence (files → env vars)
  • Optional advanced features (partial updates, rollback, gradual rollout)

§Quick Start

use hotswap_config::prelude::*;
use serde::Deserialize;

#[derive(Debug, Deserialize, Clone)]
struct AppConfig {
    server: ServerConfig,
    database: DatabaseConfig,
}

#[derive(Debug, Deserialize, Clone)]
struct ServerConfig {
    port: u16,
}

#[derive(Debug, Deserialize, Clone)]
struct DatabaseConfig {
    url: String,
}

// Load configuration with standard precedence
let config = HotswapConfig::builder()
    .with_file("config/default.yaml")
    .with_env_overrides("APP", "__")
    .build::<AppConfig>()
    .await?;

// Zero-cost reads (no locks!)
let cfg = config.get();
println!("Server port: {}", cfg.server.port);

§Features

  • Lock-free reads: Sub-10ns read latency using arc-swap
  • Atomic updates: Readers never see partial state
  • File watching: Automatic reload on file changes
  • Validation: Reject invalid configs, keep old one
  • Partial updates: JSON Patch for surgical changes
  • Rollback: Time-travel to previous configs
  • Gradual rollout: A/B test configuration changes
  • Remote sources: HTTP, etcd, Consul support
  • Secret management: Vault, AWS, GCP integration

§Feature Flags

Enable optional features in your Cargo.toml:

[dependencies]
hotswap-config = { version = "0.1", features = ["partial-updates", "rollback"] }

See the crate documentation for all available features.

Modules§

core
Core configuration management types.
error
Error types for hotswap-config.
notify
Configuration change notification system.
prelude
Convenient re-exports for common usage patterns.
sources
Configuration source implementations.