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();
48//! ```
49
50/// Error context management and accumulation
51pub mod context;
52/// Error type conversions between Result, Validation, and ComposableError
53pub mod convert;
54/// Error handling macros for context creation
55pub mod macros;
56/// Core traits for error handling and composition
57pub mod traits;
58/// ComposableError and error context structures
59pub mod types;
60/// Validation type and associated traits for error accumulation
61pub mod validation;
62
63pub use context::*;
64pub use convert::*;
65pub use traits::*;
66pub use types::*;
67pub use validation::*;