unroll-lite
Unroll loops in const contexts, declarative macro version.
Examples
The main restriction is that the macro only supports standard exclusive ranges, eg. 0..10 and -5..5, but not ..5 or 0..=10.
use unroll;
let mut a = 0;
unroll!;
assert!
A custom step size can be set:
use unroll;
let mut v = Vecnew;
unroll!;
assert!
Iteration can be reversed:
use unroll;
let mut v = Vecnew;
unroll!;
assert!
Combinations of step size and reverse iteration are also supported:
use unroll;
let mut v = Vecnew;
unroll!;
assert!;
use unroll;
let mut v = Vecnew;
unroll!;
assert!
You can use mutable and wildcard variables as the loop variable, and they act as expected.
use unroll;
let mut v = Vecnew;
unroll!;
assert!;
use unroll;
let mut a = 0;
unroll!;
assert!
The body of the loop can be any statement. This means that the following is legal, even though it is not in a regular for loop.
use unroll;
let mut a = 0;
unroll!;
assert!
use unroll;
unsafe
unroll!;
If the beginning of the range plus the step overflows the integer behaviour is undefined.
A real world example:
const
After:
use unroll;
const
Credits & License
This crates is originally a fork of const_for by Joachim EnggÄrd Nebel, licensed under the MIT License.