error_rail/
lib.rs

1//! Each submodule re-exports its public surface from here, so consumers can
2//! simply depend on `error_rail::*` or pick focused pieces as needed.
3//!
4//! # Examples
5//!
6//! ## Basic Error with Context
7//!
8//! ```
9//! use error_rail::{ComposableError, ErrorContext, group};
10//!
11//! let err = ComposableError::new("database connection failed")
12//!     .with_context(group!(
13//!         tag("db"),
14//!         metadata("retry_count", "3")
15//!     ))
16//!     .set_code(500);
17//!
18//! assert!(err.to_string().contains("database connection failed"));
19//! assert_eq!(err.error_code(), Some(500));
20//! ```
21//!
22//! ## Validation Accumulation
23//!
24//! ```
25//! use error_rail::validation::Validation;
26//!
27//! let v1: Validation<&str, i32> = Validation::Valid(10);
28//! let v2: Validation<&str, i32> = Validation::invalid("error");
29//! let combined: Validation<&str, Vec<i32>> = vec![v1, v2].into_iter().collect();
30//!
31//! assert!(combined.is_invalid());
32//! ```
33//!
34//! ## Error Pipeline
35//!
36//! ```
37//! use error_rail::{ErrorPipeline, context};
38//!
39//! let result = ErrorPipeline::<i32, &str>::new(Err("failed"))
40//!     .with_context(context!("operation: load_config"))
41//!     .with_context(context!("user_id: 42"))
42//!     .finish_boxed();
43//!
44//! if let Err(err) = result {
45//!     let chain = err.error_chain();
46//!     assert!(chain.contains("user_id: 42"));
47//!     assert!(chain.contains("operation: load_config"));
48//!     assert!(chain.contains("failed"));
49//! }
50//! ```
51#![cfg_attr(not(feature = "std"), no_std)]
52
53#[cfg(not(feature = "std"))]
54extern crate alloc;
55
56#[cfg(feature = "std")]
57extern crate std;
58
59/// Error context management and accumulation
60pub mod context;
61/// Error type conversions between Result, Validation, and ComposableError
62pub mod convert;
63/// Error handling macros for context creation
64pub mod macros;
65/// Convenience re-exports for quick starts
66pub mod prelude;
67/// Core traits for error handling and composition
68pub mod traits;
69/// ComposableError and error context structures
70pub mod types;
71/// Validation type and associated traits for error accumulation
72pub mod validation;
73
74/// Advanced API level for library authors
75pub mod advanced;
76/// Intermediate API level for service developers
77pub mod intermediate;
78
79/// Async extensions for error handling (requires `async` feature)
80#[cfg(feature = "async")]
81pub mod async_ext;
82
83/// Async prelude - all async utilities in one import (requires `async` feature)
84#[cfg(feature = "async")]
85pub mod prelude_async;
86
87/// Tower integration - Layer and Service implementations (requires `tower` feature)
88#[cfg(feature = "tower")]
89pub mod tower;
90
91// Re-export common types that might be needed at root,
92// but encourage using prelude/intermediate/advanced modules.
93pub use context::*;
94pub use convert::*;
95pub use traits::*;
96pub use types::{
97    error_formatter::ErrorFormatConfig, BoxedComposableResult, BoxedResult, ComposableError,
98    ComposableResult, ErrorContext, ErrorPipeline, ErrorVec, GroupContext, LazyContext,
99    LazyGroupContext,
100};
101pub use validation::*;