1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-License-Identifier: MIT OR Apache-2.0
//! A hexagonal architecture configuration management crate.
//!
//! This crate provides a flexible, type-safe configuration management system that can
//! read configuration from multiple sources including environment variables, YAML files,
//! command-line arguments, and remote services like etcd and Redis.
//!
//! # Architecture
//!
//! The crate follows hexagonal architecture principles:
//!
//! - **Domain Layer**: Core types and business logic (`ConfigKey`, `ConfigValue`, errors)
//! - **Ports**: Trait definitions that define interfaces (`ConfigSource`, `ConfigWatcher`)
//! - **Adapters**: Implementations for specific configuration sources (env vars, YAML, etc.)
//! - **Service**: The main configuration service that orchestrates everything
//!
//! # Features
//!
//! - **Multiple Sources**: Environment variables, YAML files, CLI arguments, etcd, Redis
//! - **Type Safety**: Type-safe conversions from string values to Rust types
//! - **Precedence**: Configurable precedence order (CLI > env > files by default)
//! - **Dynamic Reloading**: Watch for configuration changes and reload automatically
//! - **Extensible**: Easy to add new configuration sources via trait implementation
//!
//! # Feature Flags
//!
//! - `yaml`: Enable YAML file support (default)
//! - `env`: Enable environment variable support (default)
//! - `cli`: Enable command-line argument support (default)
//! - `reload`: Enable dynamic reloading with file watching
//! - `etcd`: Enable etcd remote configuration support
//! - `redis`: Enable Redis remote configuration support
//! - `remote`: Enable all remote sources (etcd + redis)
//! - `full`: Enable all features
//!
//! # Quick Start
//!
//! ```rust
//! use hexcfg::prelude::*;
//!
//! # fn main() -> Result<()> {
//! // Create a configuration service with environment variables
//! let service = DefaultConfigService::builder()
//! .with_env_vars()
//! .build()?;
//!
//! // Get a configuration value (using convenient string slice methods)
//! let value = service.get_or_default_str("app.name", "MyApp");
//! println!("Application name: {}", value.as_str());
//!
//! // Type-safe conversions
//! if let Ok(port_value) = service.get_str("app.port") {
//! let port: i32 = port_value.as_i32("app.port").unwrap_or(8080);
//! println!("Port: {}", port);
//! }
//!
//! // Check if a key exists
//! if service.has_str("app.debug") {
//! println!("Debug mode configured");
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Convenience Methods
//!
//! For ergonomic usage, the crate provides `_str` variants that accept string slices:
//! - [`ConfigurationService::get_str`](domain::ConfigurationService::get_str)
//! - [`ConfigurationService::get_or_default_str`](domain::ConfigurationService::get_or_default_str)
//! - [`ConfigurationService::has_str`](domain::ConfigurationService::has_str)
//! - [`ConfigSource::get_str`](ports::ConfigSource::get_str)
//!
//! # Examples
//!
//! See the `examples/` directory for comprehensive examples:
//! - `basic_usage.rs` - Getting started with environment variables
//! - `multi_source.rs` - Using multiple configuration sources with precedence
//! - `dynamic_reload.rs` - Dynamic configuration reloading with file watching
/// Commonly used types and traits.
///
/// This module re-exports the most commonly used types and traits for convenient access.