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//! std::fs::read_to_string("config.toml")
25//! .ctx("loading configuration")
26//! }
27//! ```
28//!
29//! ## With Lazy Context (2.1x Faster)
30//!
31//! ```
32//! use error_rail::prelude::*;
33//!
34//! fn process_user(id: u64) -> BoxedResult<(), &'static str> {
35//! let result: Result<(), &str> = Err("not found");
36//! result.ctx_with(|| format!("processing user {}", id))
37//! }
38//! ```
39
40// Macros
41pub use crate::{context, group, rail};
42
43// Core types
44pub use crate::types::lazy_context::LazyGroupContext;
45pub use crate::types::{ComposableError, ErrorContext, ErrorPipeline};
46
47// Traits
48pub use crate::traits::{BoxedResultExt, IntoErrorContext, ResultExt};
49
50// Convenient type alias
51use crate::types::alloc_type::Box;
52
53/// Convenient result type alias for functions returning boxed composable errors.
54///
55/// This is the recommended return type for public API functions as it has
56/// minimal stack footprint (8 bytes) while providing full error context.
57///
58/// # Examples
59///
60/// ```
61/// use error_rail::prelude::*;
62///
63/// fn read_file(path: &str) -> BoxedResult<String, std::io::Error> {
64/// std::fs::read_to_string(path)
65/// .ctx("reading file")
66/// }
67/// ```
68pub type BoxedResult<T, E> = Result<T, Box<ComposableError<E>>>;