#array #init #const

macro no-std array-const-fn-init

Initializes an array with constant values calculated by a const fn

2 releases

0.1.1 May 20, 2020
0.1.0 May 20, 2020

#14 in #init

Download history 3084/week @ 2023-01-26 991/week @ 2023-02-02 793/week @ 2023-02-09 738/week @ 2023-02-16 1522/week @ 2023-02-23 792/week @ 2023-03-02 969/week @ 2023-03-09 552/week @ 2023-03-16 830/week @ 2023-03-23 469/week @ 2023-03-30 486/week @ 2023-04-06 1672/week @ 2023-04-13 652/week @ 2023-04-20 362/week @ 2023-04-27 360/week @ 2023-05-04 357/week @ 2023-05-11

1,929 downloads per month
Used in enarx-shim-kvm

MIT/Apache

7KB
54 lines

array-const-fn-init

Initializes an array with constant values calculated by a const fn (usize) -> T

Requires Rust >= 1.45

Example

use array_const_fn_init::array_const_fn_init;

const fn const_double_it(i: usize) -> usize {
    i * 2
}
const ARRAY: [usize; 10] = array_const_fn_init![const_double_it; 10];
assert_eq!(ARRAY, [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]);
use array_const_fn_init::array_const_fn_init;

const fn const_vecs(i: usize) -> (u8, u8, u8) {
    (i as u8, i as u8, i as u8)
}
const ARRAY: [(u8, u8, u8); 4] = array_const_fn_init![const_vecs; 4];
assert_eq!(ARRAY, [(0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3)]);

lib.rs:

Initializes an array with constant values calculated by a const fn

Examples

use array_const_fn_init::array_const_fn_init;

const fn const_double_it(i: usize) -> usize {
    i * 2
}
const ARRAY: [usize; 10] = array_const_fn_init![const_double_it; 10];
assert_eq!(ARRAY, [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]);
use array_const_fn_init::array_const_fn_init;

const fn const_vecs(i: usize) -> (u8, u8, u8) {
    (i as u8, i as u8, i as u8)
}
const ARRAY: [(u8, u8, u8); 4] = array_const_fn_init![const_vecs; 4];
assert_eq!(ARRAY, [(0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3)]);

No runtime deps