proc_unroll 0.1.1

Proc macro to unroll for loops
Documentation

proc_unroll is a proc macro to unroll loops inside a function. It supports loops of the following forms:

  • for pat in int..int
  • for pat in &[elem, elem]

Examples

Simple example using a range:

#[proc_unroll::unroll]
fn unrolled() -> Vec<u32> {
let mut vec = Vec::new();
for x in 10..20 {
vec.push(x);
}
vec
}
assert_eq!(unrolled(), (10..20).collect::<Vec<_>>());

You can also use it in a const fn:

#[proc_unroll::unroll]
const fn inner() -> i64 {
let mut total = 0;
for x in &[5, 15, 30] {
total += *x;
}
total
}

assert_eq!(inner(), 50);