Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haraldh/array-const-fn-init
Initializes an array with constant values calculated by a `const fn`
https://github.com/haraldh/array-const-fn-init
Last synced: 3 months ago
JSON representation
Initializes an array with constant values calculated by a `const fn`
- Host: GitHub
- URL: https://github.com/haraldh/array-const-fn-init
- Owner: haraldh
- License: apache-2.0
- Created: 2020-05-20T12:58:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-02T19:52:04.000Z (over 4 years ago)
- Last Synced: 2024-09-14T09:34:36.434Z (4 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# array-const-fn-init
Initializes an array with constant values calculated by a `const fn (usize) -> T`
Requires Rust >= 1.45
# Example
```rust
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]);
``````rust
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)]);
```