rail

Macro rail 

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

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

This macro provides a convenient shorthand for creating an ErrorPipeline and immediately calling finish() 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.

§Examples

use error_rail::{rail, group};

// Simple expression
let result = rail!(Err::<(), &str>("failed"));
assert!(result.is_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")
)));