Crates.io | array-fu |
lib.rs | array-fu |
version | 0.0.1-alpha |
source | src |
created_at | 2022-04-28 18:55:31.68118 |
updated_at | 2022-04-28 18:59:51.317847 |
description | Construct arrays using simple syntax |
homepage | https://github.com/zakarumych/array-fu |
repository | https://github.com/zakarumych/array-fu |
max_upload_size | |
id | 576943 |
size | 26,774 |
This crate defines array!
and other macros that can construct arrays.
Use simple syntax, make it more complex as requirements change.
array!
macro constructs arrays by repeating expression execution, possibly with enumeration bound to provided pattern.
use array_fu::array;
use rand::random;
let values: [f32; 2] = array![random(); 2];
This also means that expression type may not be Copy
or event Clone
.
use array_fu::array;
# use std::sync::Mutex;
let values = array![Mutex::new(1); 2];
See more examples in the array!
macro documentation.
collect_array!
macro constructs arrays by repeating expression execution with elements from iterators bound to provided patterns.
use array_fu::collect_array;
let opt = collect_array![x in 1.., y in 2.. => x + y; where x * y > 10; 3];
assert_eq!(opt, Some([7, 9, 11]));
use array_fu::collect_array;
let values = collect_array![(x, y) in [(1, 2), (3, 4), (5, 6)] => x + y; 3];
assert_eq!(values, Some([3, 7, 11]));
See more examples in the collect_array!
macro documentation.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.