Inline error recovery

Actually, try trait v2 will allow you do define a method for something like this yourself (even in an external crate). You would need to write something like baz().prop_ok()? instead of baz()!? but that’s probably way more readable anyways. [“prop” is short for “propagate” in the method name I use here.]

I have a proof of concept implementation, allowing for

fn foo() -> Result<u32, bool> {
    Ok(42)
}

fn bar() -> Result<(), char> {
    Ok(())
}


fn baz() -> Result<u32, char> {
    let x = foo().prop_ok()?;
    // x is bool, but no type annotation needed
    bar()?;
    Err('e')
}

(playground)

3 Likes