Attribute Macro hb_macros::convert_error

source ·
#[convert_error]
Expand description

Converts Errors returned by the function into the correct type for the function as well adding a context message provided. This macro will change the following function…

#[convert_error]
fn basic_exampleerror() -> Result<(), ExampleError> {
    if io_error()? {
        return example_error().map_err(|e| e.msg("msgs are great"));
    }
    example_error()
}

into…

fn basic_exampleerror() -> Result<(), ExampleError> {
    #[allow(unreachable_code)]
    let ret: Result<(), ExampleError> = {
           #[warn(unreachable_code)]
        if hb_error::ConvertInto::Result<(), ExampleError>::convert(io_error())? {
            return hb_error::ConvertInto::Result<(), ExampleError>::convert(example_error());
        }
        example_error()
    };
    #[allow(unreachable_code)]
    ret
}