Expand description
Error handling macros for context creation
Ergonomic macros for creating lazy or structured ErrorContext.
These macros provide convenient shortcuts for attaching rich metadata to errors:
crate::rail- Wraps aResult-producing block and converts it into aBoxedComposableResultviaErrorPipeline::finish_boxed. Always returns boxed errors.crate::rail_unboxed- Wraps aResult-producing block and converts it into an unboxedComposableResultviaErrorPipeline::finish.crate::context- Defers formatting until the context is consumed, avoiding unnecessary allocations on the success path.crate::group- Creates a lazily-evaluated grouped context that combines multiple fields (message, tags, location, metadata) into one cohesive unit while deferring all formatting until the error occurs.
§Examples
use error_rail::{context, rail, rail_unboxed, group, ErrorPipeline};
let result: Result<(), &str> = Err("failed");
let pipeline = ErrorPipeline::new(result)
.with_context(context!("user_id: {}", 123))
.with_context(group!(
tag("auth"),
location(file!(), line!()),
metadata("retry_count", "3")
))
.finish_boxed();
assert!(pipeline.is_err());
// rail! - ALWAYS returns boxed error (8 bytes stack size)
let boxed_result = rail!({
Err::<(), &str>("failed")
});
// rail_unboxed! - returns unboxed error (larger stack size)
let unboxed_result = rail_unboxed!({
Err::<(), &str>("failed")
});§Choosing Between rail! and rail_unboxed!
- Use
rail!for public APIs and most cases - smaller stack footprint (8 bytes) - Use
rail_unboxed!for internal code or performance-critical paths where you want to avoid heap allocation