try_more 0.1.0

Expand your possibilities with the Try `?` Operator
Documentation

Expand your possibilities with the Try ? Operator

Have you ever found yourself writing a function which may return early based on some condition?

fn my_function() {
// ...

# let condition_a = false;
if condition_a {
return;
}

// ...

# let condition_b = true;
if condition_b {
return;        
}

// ...
}

It doesn't look Rusty, right? This crate offers an extension trait to be able to convert from a bool to a ControlFlow and leverage the mighty power of ? to get rid of those checks:

# use core::ops::ControlFlow;
# use try_more::BoolFlow;

fn my_function() -> ControlFlow<()> {
// ...
# let condition_a = false;
BoolFlow::r#break(condition_a)?;
// ...
# let condition_b = true;
condition_b.r#break()?;

// ...
# ControlFlow::Continue(())
}

There's also other methods besides [continue][BoolFlow::continue] and [break][BoolFlow::break] which allows to control the value which is passed to the Break variant.