#[fatal_fn]Expand description
An attribute macro that wraps a function’s body in the fatal! macro.
This macro allows you to specify an optional reason for the fatal error using the attribute argument.
§Example
use thiserror::Error;
use impass::{fatal, fatal_fn};
// Declare an error type for demonstration purposes.
#[derive(Error, Debug)]
pub enum MyError {
#[error("This operation failed")]
OperationFailed
}
// A fallible function for demonstration.
fn might_fail(value: i32) -> Result<i32, MyError> {
if value < 10 {
Err(MyError::OperationFailed)
} else {
Ok(value * 2)
}
}
// Using the `fatal_fn` macro to wrap a function.
#[fatal_fn(reason = "Critical failure in function execution")]
fn example_function() -> i32 {
let value = might_fail(15)?;
Ok(value)
}
// The above function is equivalent to:
fn example_function_actual() -> i32 {
fatal! {
#![reason("Critical failure in function execution")]
let value = might_fail(15)?;
Ok(value)
}
}