ctrl_macros

Crates.ioctrl_macros
lib.rsctrl_macros
version0.1.0
sourcesrc
created_at2022-08-02 17:00:03.026125
updated_at2022-08-02 17:00:03.026125
descriptionControl flow macros for Option and Result
homepagehttps://github.com/gajop/ctrl_macros
repositoryhttps://github.com/gajop/ctrl_macros
max_upload_size
id637457
size7,877
Gajo Petrovic (gajop)

documentation

README

README

Control macros for Option and Result.

Helps you change this:

fn returns_early_with_value(input: Result<i32, String>) {
    // Early return when something is wrong.
    let input: i32 = match input {
        Ok(value) => value,
        Err(_) => return,
    };

    // Use it normally below...
    println!("Input is: {}", input);
}

into

use ctrl_macros::{ok_or_return};

fn returns_early_with_value(input: Result<i32, String>) {
    let input: i32 = ok_or_return!(input);
    println!("Input is: {}", input);
}

Examples

let x = ok_or!(x, return 42);
for i in 0..5 {
    let x = ok_or_continue!(x);
}
for i in 0..5 {
    let x = ok_or_break!(x);
}

and some_or equivalents

some_or!
some_or_return!
some_or_continue!
some_or_break!

License

ctrl_macros is dual licensed under either:

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

Commit count: 3

cargo fmt