Macro simple_error::try_with [] [src]

macro_rules! try_with {
    ($expr: expr, $str: expr) => { ... };
}

Helper macro for unwrapping Result values while returning early with a newly constructed SimpleError if the value of the expression is Err. Can only be used in functions that return Result<_, SimpleError>.

Examples

use self::simple_error::SimpleError;

fn try_block(result: Result<(), SimpleError>, s: &str) -> Result<(), SimpleError> {
    Ok(try_with!(result, s))
}

// Above is equivalent to below.

fn try_block_equivalent(result: Result<(), SimpleError>, s: &str) -> Result<(), SimpleError> {
    match result {
        Ok(v) => Ok(v),
        Err(e) => {
            return Err(SimpleError::with(s, e));
        },
    }
}