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// Macros
51pub use crate::{context, group, rail, rail_unboxed};
52
53// Core types (Beginner friendly)
54pub use crate::types::{ComposableError, ErrorContext, ErrorPipeline};
55
56// Traits (Essential for method syntax)
57pub use crate::traits::{BoxedResultExt, IntoErrorContext, ResultExt};
58
59// Convenient type alias
60use crate::types::alloc_type::Box;
61
62/// Convenient result type alias for functions returning boxed composable errors.
63///
64/// This is the recommended return type for public API functions as it has
65/// minimal stack footprint (8 bytes) while providing full error context.
66///
67/// # Examples
68///
69/// ```
70/// use error_rail::prelude::*;
71///
72/// fn read_file(path: &str) -> BoxedResult<String, std::io::Error> {
73/// // In a real app, this would be std::fs::read_to_string(path)
74/// Err(std::io::Error::new(std::io::ErrorKind::Other, "mock error"))
75/// .ctx("reading file")
76/// }
77///
78/// assert!(read_file("test.txt").is_err());
79/// ```
80pub type BoxedResult<T, E> = Result<T, Box<ComposableError<E>>>;