Crates.io | unroll-fn |
lib.rs | unroll-fn |
version | 0.1.1 |
source | src |
created_at | 2022-03-12 13:26:29.076281 |
updated_at | 2022-03-12 13:34:42.521857 |
description | A generic unrollling function. |
homepage | |
repository | https://github.com/kitegi/unroll/ |
max_upload_size | |
id | 548762 |
size | 3,733 |
unroll-fn
An generic unroll function that takes a callable and calls it N
times.
[dependencies]
unroll-fn = "0.1"
use unroll::unroll;
fn main() {
let arr = [1, 10, 100];
let mut sum = 0;
// Expands to:
//
// sum += arr[0];
// sum += arr[1];
// sum += arr[2];
//
unroll::<3, _>(|i| sum += arr[i]);
assert_eq!(sum, 111);
}