chie_shared/config/feature_flags.rs
1//! Feature flags configuration
2
3use serde::{Deserialize, Serialize};
4
5/// Feature flags for runtime feature toggling
6///
7/// # Examples
8///
9/// Using the default configuration (production-ready features enabled):
10/// ```
11/// use chie_shared::FeatureFlags;
12///
13/// let flags = FeatureFlags::default();
14/// assert!(!flags.experimental);
15/// assert!(!flags.beta);
16/// assert!(flags.compression_optimization);
17/// assert!(flags.adaptive_retry);
18/// assert!(!flags.has_unstable_features());
19/// ```
20///
21/// Using preset configurations:
22/// ```
23/// use chie_shared::FeatureFlags;
24///
25/// // All features disabled (minimal mode)
26/// let minimal = FeatureFlags::none();
27/// assert!(!minimal.compression_optimization);
28/// assert!(!minimal.has_diagnostic_features());
29///
30/// // All features enabled (debug/testing mode)
31/// let all = FeatureFlags::all();
32/// assert!(all.experimental);
33/// assert!(all.debug_mode);
34/// assert!(all.has_unstable_features());
35/// assert!(all.has_diagnostic_features());
36/// ```
37///
38/// Building a custom configuration:
39/// ```
40/// use chie_shared::FeatureFlagsBuilder;
41///
42/// let flags = FeatureFlagsBuilder::new()
43/// .experimental(true)
44/// .performance_profiling(true)
45/// .enhanced_telemetry(true)
46/// .build();
47///
48/// assert!(flags.experimental);
49/// assert!(flags.performance_profiling);
50/// assert!(flags.has_unstable_features());
51/// assert!(flags.has_diagnostic_features());
52/// ```
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct FeatureFlags {
55 /// Enable experimental features
56 pub experimental: bool,
57 /// Enable beta features
58 pub beta: bool,
59 /// Enable enhanced telemetry
60 pub enhanced_telemetry: bool,
61 /// Enable performance profiling
62 pub performance_profiling: bool,
63 /// Enable debug mode
64 pub debug_mode: bool,
65 /// Enable compression optimization
66 pub compression_optimization: bool,
67 /// Enable adaptive retry
68 pub adaptive_retry: bool,
69}
70
71impl Default for FeatureFlags {
72 fn default() -> Self {
73 Self {
74 experimental: false,
75 beta: false,
76 enhanced_telemetry: false,
77 performance_profiling: false,
78 debug_mode: false,
79 compression_optimization: true,
80 adaptive_retry: true,
81 }
82 }
83}
84
85impl FeatureFlags {
86 /// Create a new feature flags configuration with all features disabled
87 #[must_use]
88 pub const fn none() -> Self {
89 Self {
90 experimental: false,
91 beta: false,
92 enhanced_telemetry: false,
93 performance_profiling: false,
94 debug_mode: false,
95 compression_optimization: false,
96 adaptive_retry: false,
97 }
98 }
99
100 /// Create a new feature flags configuration with all features enabled
101 #[must_use]
102 pub const fn all() -> Self {
103 Self {
104 experimental: true,
105 beta: true,
106 enhanced_telemetry: true,
107 performance_profiling: true,
108 debug_mode: true,
109 compression_optimization: true,
110 adaptive_retry: true,
111 }
112 }
113
114 /// Check if any experimental or beta feature is enabled
115 #[must_use]
116 pub const fn has_unstable_features(&self) -> bool {
117 self.experimental || self.beta
118 }
119
120 /// Check if any diagnostic feature is enabled
121 #[must_use]
122 pub const fn has_diagnostic_features(&self) -> bool {
123 self.debug_mode || self.performance_profiling || self.enhanced_telemetry
124 }
125}
126
127/// Builder for `FeatureFlags`
128///
129/// # Examples
130///
131/// Building flags for development environment:
132/// ```
133/// use chie_shared::FeatureFlagsBuilder;
134///
135/// let flags = FeatureFlagsBuilder::new()
136/// .beta(true)
137/// .debug_mode(true)
138/// .performance_profiling(true)
139/// .enhanced_telemetry(true)
140/// .build();
141///
142/// assert!(flags.beta);
143/// assert!(flags.debug_mode);
144/// assert!(flags.has_diagnostic_features());
145/// ```
146///
147/// Building flags for staging environment:
148/// ```
149/// use chie_shared::FeatureFlagsBuilder;
150///
151/// let flags = FeatureFlagsBuilder::new()
152/// .beta(true)
153/// .enhanced_telemetry(true)
154/// .compression_optimization(true)
155/// .adaptive_retry(true)
156/// .build();
157///
158/// assert!(flags.beta);
159/// assert!(!flags.experimental); // Not ready for experimental
160/// assert!(flags.enhanced_telemetry);
161/// ```
162#[derive(Debug, Default)]
163pub struct FeatureFlagsBuilder {
164 config: FeatureFlags,
165}
166
167impl FeatureFlagsBuilder {
168 /// Create a new builder with default values
169 #[must_use]
170 pub fn new() -> Self {
171 Self::default()
172 }
173
174 /// Enable or disable experimental features
175 #[must_use]
176 pub const fn experimental(mut self, enable: bool) -> Self {
177 self.config.experimental = enable;
178 self
179 }
180
181 /// Enable or disable beta features
182 #[must_use]
183 pub const fn beta(mut self, enable: bool) -> Self {
184 self.config.beta = enable;
185 self
186 }
187
188 /// Enable or disable enhanced telemetry
189 #[must_use]
190 pub const fn enhanced_telemetry(mut self, enable: bool) -> Self {
191 self.config.enhanced_telemetry = enable;
192 self
193 }
194
195 /// Enable or disable performance profiling
196 #[must_use]
197 pub const fn performance_profiling(mut self, enable: bool) -> Self {
198 self.config.performance_profiling = enable;
199 self
200 }
201
202 /// Enable or disable debug mode
203 #[must_use]
204 pub const fn debug_mode(mut self, enable: bool) -> Self {
205 self.config.debug_mode = enable;
206 self
207 }
208
209 /// Enable or disable compression optimization
210 #[must_use]
211 pub const fn compression_optimization(mut self, enable: bool) -> Self {
212 self.config.compression_optimization = enable;
213 self
214 }
215
216 /// Enable or disable adaptive retry
217 #[must_use]
218 pub const fn adaptive_retry(mut self, enable: bool) -> Self {
219 self.config.adaptive_retry = enable;
220 self
221 }
222
223 /// Build the feature flags configuration
224 #[must_use]
225 pub const fn build(self) -> FeatureFlags {
226 self.config
227 }
228}