unroll_range 0.2.0

Repeats a block of code for each number in a specified range.
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 4.28 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.04 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • PSeitz

unroll_range

unroll_range is a Rust macro designed to facilitate the repetition of a block of code for each number within a specified range. This macro is particularly useful for tasks that require repetitive operations over a set of values, like iterations for testing, data processing, or generating output.

Usage

To use unroll_range, include it in your Rust project. Call the macro with a range (inclusive or exclusive) and a closure that performs the operations you wish to repeat.

Parameters

  • $range: A Rust range expression (either inclusive or exclusive) over which the block will be repeated.
  • $block: A closure that takes a single parameter i and contains the code to execute for each iteration.

Example

Here's how you can use unroll_range with an inclusive range:

unroll_range!(1..=3, |i| {
    println!("Number: {}", i);
});

Comparison

crunchy

crunchy works fine, but adds a lot of boilerplate code, unnecessary if conditions.

repeated

repeated doesn't scope the block, so constants can't be used. It's also using procmacro, which seems to be a bit slower than a macro_rules macro.