rail

Macro rail 

Source
macro_rules! rail {
    ($expr:expr $(,)?) => { ... };
}
Expand description

Wraps a Result-producing expression or block and converts it into a BoxedComposableResult.

⚠️ IMPORTANT: This macro ALWAYS returns a boxed composable result. The error type is wrapped in a Box<ComposableError<E>> to reduce stack size. If you need an unboxed result, use rail_unboxed! instead.

This macro provides a convenient shorthand for creating an ErrorPipeline and immediately calling finish_boxed() to box the result. It accepts either a single expression or a block of code that produces a Result.

§Syntax

  • rail!(expr) - Wraps a single Result-producing expression
  • rail!({ ... }) - Wraps a block that produces a Result

§Returns

A BoxedComposableResult<T, E> where the error type is wrapped in a ComposableError and boxed.

§Examples

use error_rail::{rail, group};

// Simple expression - ALWAYS returns boxed error
let result = rail!(Err::<(), &str>("failed"));
assert!(result.is_err());
// Error type is Box<ComposableError<&str>>
let _: Box<error_rail::ComposableError<&str>> = result.unwrap_err();

// Block syntax with multiple statements
let result = rail!({
    let value = std::fs::read_to_string("config.txt");
    value
});

// Using with group! macro for structured context
let result = rail!({
    std::fs::read_to_string("config.txt")
})
.map_err(|e| e.with_context(group!(
    tag("config"),
    location(file!(), line!()),
    metadata("file", "config.txt")
)));