error_rail/
lib.rs

1//! Composable, metadata-friendly error handling utilities.
2//!
3//! `error-rail` focuses on three pillars:
4//! 1. **Structured context** – enrich any error with layered metadata
5//!    using [`context!`] helpers and macros such as [`location!`] and [`tag!`].
6//! 2. **Composable collectors** – aggregate successes/failures with the
7//!    [`validation`] module and convert between `Result`, `Validation`, and
8//!    `ComposableError` via [`convert`].
9//! 3. **Ergonomic traits/macros** – glue traits in [`traits`] and shortcuts
10//!    in [`macros`] keep the API light-weight.
11//!
12//! Each submodule re-exports its public surface from here, so consumers can
13//! simply depend on `error_rail::*` or pick focused pieces as needed.
14//!
15//! # Examples
16//!
17//! ## Basic Error with Context
18//!
19//! ```
20//! use error_rail::{ComposableError, ErrorContext, context, location, tag};
21//!
22//! let err = ComposableError::new("database connection failed")
23//!     .with_context(tag!("db"))
24//!     .with_context(location!())
25//!     .set_code(500);
26//! ```
27//!
28//! ## Validation Accumulation
29//!
30//! ```
31//! use error_rail::validation::Validation;
32//!
33//! let v1: Validation<&str, i32> = Validation::Valid(10);
34//! let v2: Validation<&str, i32> = Validation::invalid("error");
35//! let combined: Validation<&str, Vec<i32>> = vec![v1, v2].into_iter().collect();
36//! assert!(combined.is_invalid());
37//! ```
38//!
39//! ## Error Pipeline
40//!
41//! ```
42//! use error_rail::{ErrorPipeline, context};
43//!
44//! let result = ErrorPipeline::<i32, &str>::new(Err("failed"))
45//!     .with_context(context!("operation: load_config"))
46//!     .with_context(context!("user_id: 42"))
47//!     .finish_boxed();
48//!
49//! if let Err(err) = result {
50//!     eprintln!("{}", err.error_chain());
51//!     // Output: user_id: 42 -> operation: load_config -> failed
52//! }
53//! ```
54
55/// Error context management and accumulation
56pub mod context;
57/// Error type conversions between Result, Validation, and ComposableError
58pub mod convert;
59/// Error handling macros for context creation
60pub mod macros;
61/// Core traits for error handling and composition
62pub mod traits;
63/// ComposableError and error context structures
64pub mod types;
65/// Validation type and associated traits for error accumulation
66pub mod validation;
67
68pub use context::*;
69pub use convert::*;
70pub use traits::*;
71pub use types::*;
72pub use validation::*;