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