An interesting idea! I think it can definitely “bake” in the cargo-verse for a while before we consider std inclusion.
Perhaps this could be named in reference to “if guards” that one sees in some functions. That is:
fn foo() {
if a { return bar; }
if b { return baz; }
// normal logic, which can assume that a and b are false
}
try_err and try_ok are a bit weird to me because I don’t know which is which.
We could maybe just consider and! and or!.
fn parse_width(input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> {
or!(parse_length(input).map(LengthOrPercentageOrAuto::Length));
or!(parse_percentage(input).map(LengthOrPercentageOrAuto::Percentage));
or!(parse_keyword(input, "auto").map(|_| LengthOrPercentageOrAuto::Auto));
Err(());
}
fn chain(a: B, context: &Context) -> Result<D, E> {
let b = and!(compute_b(a, context));
let c = and!(compute_c(b, context));
let d = and!(compute_d(c, context));
Ok(d)
}