Attribute Macro attempted::attempt

source · []
#[attempt]
Expand description

Wraps the function block such that it returns an Option. If None is returned, the function will return the Default value for the return type.

Examples

fn positive(x: i32) -> Option<i32> {
    if x > 0 {
        Some(x)
    } else {
        None
    }
}

#[attempt]
fn test() {
    // try something
    let x = positive(13)?;
     
    // do something with x
    println!("{} is positive", x);
}