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 singleResult-producing expressionrail!({ ... })- Wraps a block that produces aResult
§Returns
A BoxedComposableResult<T, E> where the error type
is wrapped in a ComposableError.
§Examples
use error_rail::{rail, ErrorContext};
// 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
});
// Chaining with context after rail!
let result = rail!(Err::<(), &str>("io error"))
.map_err(|e| e.with_context(ErrorContext::tag("disk")));