ctrl_macros 0.1.0

Control flow macros for Option and Result
Documentation
  • Coverage
  • 0%
    0 out of 9 items documented0 out of 8 items with examples
  • Size
  • Source code size: 7.87 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 271.13 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • gajop/ctrl_macros
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • gajop

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.