#rfc #shim #break #block #control-flow

no-std breakable-block

A shim library for a stable implementation of what is proposed in RFC 2046

1 stable release

1.0.0 Nov 6, 2021

#1558 in Rust patterns

MIT/Apache

8KB

breakable-block

License: MIT/Apache-2.0 # Issues Crates.io Crate Downloads

A shim library for a stable implementation of what is proposed in RFC 2046, allowing for short-circuit control flow without needing to return in a function or break in a loop.

When the RFC is stabilized, this crate will be deprecated. If you don't need to work on stable, you can use

#![feature(label_break_value)]

in your crate root to enable the functionality instead.

This crate has no dependencies.

How to Use It

Here's an example, lifted straight from the RFC documentation with only minor modifications:

use breakable_block::breakable;

breakable!('block: {
    do_thing();
    if condition_not_met() {
        break 'block;
    }
    do_next_thing();
    if condition_not_met() {
        break 'block;
    }
    do_last_thing();
});

The only difference in syntax from the example in the RFC is the wrapping macro call.

Project License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in breakable-block by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps