error_rail/
prelude.rs

1//! Convenience re-exports for common usage patterns.
2//!
3//! This prelude module provides the most commonly used items for quick starts.
4//! Import everything with:
5//!
6//! ```
7//! use error_rail::prelude::*;
8//! ```
9//!
10//! # What's Included
11//!
12//! - **Macros**: [`context!`], [`group!`], [`rail!`]
13//! - **Types**: [`ComposableError`], [`ErrorContext`], [`ErrorPipeline`], [`LazyGroupContext`]
14//! - **Traits**: [`ResultExt`], [`BoxedResultExt`], [`IntoErrorContext`]
15//!
16//! # Examples
17//!
18//! ## 30-Second Quick Start
19//!
20//! ```
21//! use error_rail::prelude::*;
22//!
23//! fn load_config() -> BoxedResult<String, std::io::Error> {
24//!     // Simulate an error
25//!     let err = std::io::Error::new(std::io::ErrorKind::NotFound, "config not found");
26//!     Err(err).ctx(group!(
27//!         message("loading configuration"),
28//!         location(file!(), line!())
29//!     ))
30//! }
31//!
32//! let result = load_config();
33//! assert!(result.is_err());
34//! ```
35//!
36//! ## With Lazy Context (2.1x Faster)
37//!
38//! ```
39//! use error_rail::prelude::*;
40//!
41//! fn process_user(id: u64) -> BoxedResult<(), &'static str> {
42//!     let result: Result<(), &str> = Err("not found");
43//!     result.ctx_with(|| format!("processing user {}", id))
44//! }
45//!
46//! let result = process_user(100);
47//! assert!(result.is_err());
48//! ```
49
50// =============================================================================
51// Re-export List (for explicit imports in large projects)
52// =============================================================================
53// use error_rail::prelude::{
54//     // Macros
55//     context, group, rail, rail_unboxed,
56//     // Types
57//     BoxedResult, ComposableError, ErrorContext, ErrorPipeline,
58//     // Traits
59//     BoxedResultExt, IntoErrorContext, ResultExt,
60// };
61// =============================================================================
62
63// Macros
64pub use crate::{context, group, rail, rail_unboxed};
65
66// Core types
67pub use crate::types::{ComposableError, ErrorContext, ErrorPipeline};
68
69// Traits (Essential for method syntax)
70pub use crate::traits::{BoxedResultExt, IntoErrorContext, ResultExt};
71
72// Convenient type alias
73use crate::types::alloc_type::Box;
74
75/// Convenient result type alias for functions returning boxed composable errors.
76///
77/// This is the recommended return type for public API functions as it has
78/// minimal stack footprint (8 bytes) while providing full error context.
79///
80/// # Examples
81///
82/// ```
83/// use error_rail::prelude::*;
84///
85/// fn read_file(path: &str) -> BoxedResult<String, std::io::Error> {
86///    // In a real app, this would be std::fs::read_to_string(path)
87///    Err(std::io::Error::new(std::io::ErrorKind::Other, "mock error"))
88///         .ctx("reading file")
89/// }
90///
91/// assert!(read_file("test.txt").is_err());
92/// ```
93pub type BoxedResult<T, E> = Result<T, Box<ComposableError<E>>>;