unroll_range

Crates.iounroll_range
lib.rsunroll_range
version0.2.0
sourcesrc
created_at2023-11-22 08:48:43.919664
updated_at2023-11-22 08:53:47.104506
descriptionRepeats a block of code for each number in a specified range.
homepagehttps://github.com/pseitz/unroll_range
repositoryhttps://github.com/pseitz/unroll_range
max_upload_size
id1044983
size4,618
(PSeitz)

documentation

README

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.

Commit count: 0

cargo fmt