Crates.io | unroll_range |
lib.rs | unroll_range |
version | 0.2.0 |
source | src |
created_at | 2023-11-22 08:48:43.919664 |
updated_at | 2023-11-22 08:53:47.104506 |
description | Repeats a block of code for each number in a specified range. |
homepage | https://github.com/pseitz/unroll_range |
repository | https://github.com/pseitz/unroll_range |
max_upload_size | |
id | 1044983 |
size | 4,618 |
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.
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.
$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.Here's how you can use unroll_range
with an inclusive range:
unroll_range!(1..=3, |i| {
println!("Number: {}", i);
});
crunchy works fine, but adds a lot of boilerplate code, unnecessary if conditions.
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.