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#![cfg_attr(not(feature = "std"), no_std)]
55
56#[cfg(not(feature = "std"))]
57extern crate alloc;
58
59#[cfg(feature = "std")]
60extern crate std;
61
62/// Error context management and accumulation
63pub mod context;
64/// Error type conversions between Result, Validation, and ComposableError
65pub mod convert;
66/// Error handling macros for context creation
67pub mod macros;
68/// Core traits for error handling and composition
69pub mod traits;
70/// ComposableError and error context structures
71pub mod types;
72/// Validation type and associated traits for error accumulation
73pub mod validation;
74
75pub use context::*;
76pub use convert::*;
77pub use traits::*;
78pub use types::*;
79pub use validation::*;