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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
//! Convenient re-exports for common premortem usage.
//!
//! # Quick Start
//!
//! For most users, import the prelude:
//!
//! ```ignore
//! use premortem::prelude::*;
//! use serde::Deserialize;
//!
//! #[derive(Debug, Deserialize)]
//! struct AppConfig {
//! host: String,
//! port: u16,
//! }
//!
//! impl Validate for AppConfig {
//! fn validate(&self) -> ConfigValidation<()> {
//! if self.port > 0 {
//! Validation::Success(())
//! } else {
//! Validation::fail_with(ConfigError::ValidationError {
//! path: "port".to_string(),
//! source_location: None,
//! value: Some(self.port.to_string()),
//! message: "port must be positive".to_string(),
//! })
//! }
//! }
//! }
//!
//! fn main() -> Result<(), ConfigErrors> {
//! let config = Config::<AppConfig>::builder()
//! .source(Toml::file("config.toml"))
//! .source(Env::new().prefix("APP"))
//! .build()?;
//!
//! println!("Running on {}:{}", config.host, config.port);
//! Ok(())
//! }
//! ```
//!
//! # Import Patterns
//!
//! ## Quick Start (Recommended)
//!
//! ```ignore
//! use premortem::prelude::*;
//! ```
//!
//! ## Selective Imports
//!
//! Import only what you need:
//!
//! ```ignore
//! use premortem::{Config, Validate};
//! use premortem::error::ConfigErrors;
//! ```
//!
//! ## Advanced: Direct Stillwater Access
//!
//! For custom sources or advanced patterns:
//!
//! ```ignore
//! use premortem::prelude::*;
//! use stillwater::Effect; // Direct stillwater access for custom sources
//! ```
// ============================================================================
// Stillwater re-exports (core functional programming types)
// ============================================================================
/// Result type with error accumulation. Use `Validation::all()` to combine
/// multiple validations and collect ALL errors.
///
/// # Example
///
/// ```ignore
/// use premortem::prelude::*;
///
/// let result = Validation::all((
/// validate_host(&config.host),
/// validate_port(config.port),
/// ));
/// ```
pub use Validation;
/// Trait for combining values. `ConfigErrors` implements this for error accumulation.
///
/// When multiple validations fail, their errors are combined using `Semigroup::combine`.
pub use Semigroup;
/// Guaranteed non-empty collection. Underlying type for `ConfigErrors`.
///
/// This ensures that error collections always have at least one error,
/// preventing "empty error list" bugs.
pub use NonEmptyVec;
// Re-export stillwater predicates for composable validation (stillwater 0.13.0+)
pub use *;
// ============================================================================
// Error types
// ============================================================================
/// Individual configuration error with source location.
pub use crateConfigError;
/// Non-empty collection of errors. Implements `Semigroup` for accumulation.
///
/// Use `ConfigErrors::single()` to create from one error, or
/// `ConfigErrors::from_vec()` for multiple.
pub use crateConfigErrors;
/// Type alias: `Validation<T, ConfigErrors>`. The standard result type.
///
/// All premortem APIs use this type for validation results.
pub use crateConfigValidation;
/// Extension trait for creating failing validations easily.
pub use crateConfigValidationExt;
/// Location where a configuration value originated.
///
/// Tracks source file, line, and column for precise error reporting.
pub use crateSourceLocation;
/// Kinds of source loading errors.
pub use crateSourceErrorKind;
/// Group errors by their source for organized reporting.
pub use crategroup_by_source;
// ============================================================================
// Core config types
// ============================================================================
/// The main configuration container wrapping validated config.
///
/// Use `Config::builder()` to construct configuration from sources.
pub use crateConfig;
/// Builder for constructing configuration from multiple sources.
pub use crateConfigBuilder;
// ============================================================================
// Sources
// ============================================================================
/// Trait for configuration sources. Implement for custom sources.
pub use crateSource;
/// Intermediate representation of configuration values.
pub use crateConfigValues;
/// Pure function to merge multiple ConfigValues by priority.
pub use cratemerge_config_values;
/// JSON file configuration source (requires `json` feature).
pub use crateJson;
/// TOML file configuration source (requires `toml` feature).
pub use crateToml;
/// YAML file configuration source (requires `yaml` feature).
pub use crateYaml;
/// Environment variable configuration source.
pub use crateEnv;
/// Default values configuration source.
pub use crateDefaults;
/// Partial defaults builder for specific paths.
pub use cratePartialDefaults;
// ============================================================================
// Environment abstractions
// ============================================================================
/// Trait for abstracting I/O operations. Enables testable configuration loading.
pub use crateConfigEnv;
/// Real environment implementation for production use.
pub use crateRealEnv;
/// Mock environment for testing.
pub use crateMockEnv;
// ============================================================================
// Validation
// ============================================================================
/// Trait for types that can be validated.
///
/// Implement this trait to add custom validation logic to your config types.
pub use crateValidate;
/// Trait for individual validators.
pub use crateValidator;
/// Validate a field against multiple validators.
pub use cratevalidate_field;
/// Validate a nested struct with path context.
pub use cratevalidate_nested;
/// Validate an optional nested struct.
pub use cratevalidate_optional_nested;
/// Create a custom validator from a pure function.
pub use cratecustom;
/// Conditional validator that only runs when a condition is true.
pub use crateWhen;
// ============================================================================
// Predicate-Validator Bridge (stillwater 0.13.0+)
// ============================================================================
/// Convert a stillwater predicate into a premortem validator.
///
/// This enables using composable predicates from stillwater 0.13.0+ within
/// premortem's validation framework.
///
/// # Example
///
/// ```ignore
/// use premortem::prelude::*;
///
/// let validator = from_predicate(not_empty().and(len_min(3)));
/// validate_field(&username, "username", &[&validator])
/// ```
pub use cratefrom_predicate;
/// Validate a value using a predicate with a custom error message.
///
/// This is a convenience function that makes predicate-based validation
/// ergonomic with custom error messages.
///
/// # Example
///
/// ```ignore
/// use premortem::prelude::*;
///
/// validate_with_predicate(
/// &port,
/// "port",
/// between(1, 65535),
/// "port must be between 1 and 65535"
/// )
/// ```
pub use cratevalidate_with_predicate;
// ============================================================================
// Built-in validators
// ============================================================================
/// Built-in validators for common validation patterns.
// ============================================================================
// Value types
// ============================================================================
/// Untyped configuration value.
pub use crateValue;
/// Configuration value with source location tracking.
pub use crateConfigValue;
// ============================================================================
// Tracing (debugging configuration origin)
// ============================================================================
/// Configuration with tracing information.
pub use crateTracedConfig;
/// A value with its source information.
pub use crateTracedValue;
/// Trace of a single configuration value.
pub use crateValueTrace;
/// Builder for collecting trace data during config building.
pub use crateTraceBuilder;
// ============================================================================
// Pretty printing
// ============================================================================
/// Options for pretty printing errors.
pub use cratePrettyPrintOptions;
/// Color output option.
pub use crateColorOption;
/// Trait extension for easy error handling with pretty printing.
///
/// Provides `unwrap_or_exit()` for CLI applications.
pub use crateValidationExt;
// ============================================================================
// Optional features
// ============================================================================
/// Hot-reloadable configuration (requires `watch` feature).
pub use crateWatchedConfig;
/// File watcher for configuration changes (requires `watch` feature).
pub use crateConfigWatcher;
/// Events emitted during configuration watching (requires `watch` feature).
pub use crateConfigEvent;
// ============================================================================
// Derive macro
// ============================================================================
/// Derive macro for `Validate` trait (requires `derive` feature).
pub use Validate as DeriveValidate;