2 releases
0.1.1 | Apr 21, 2020 |
---|---|
0.1.0 | Apr 21, 2020 |
#7 in #unroll
7KB
141 lines
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);
Dependencies
~1.5MB
~36K SLoC