macro_rules! bst_array {
() => { ... };
($value:expr; $count:expr) => { ... };
($($elem:expr),+ $(,)?) => { ... };
(with_allocator: $alloc:ty => $value:expr; $count:expr) => { ... };
(with_allocator: $alloc:ty => $($elem:expr),+ $(,)?) => { ... };
(@count $x:expr) => { ... };
}
Expand description
Creates a BSTArray
with syntax similar to the standard vec!
macro.
§Examples
Create an array from a list of values:
let arr = bst_array![1_u32, 2, 3];
assert_eq!(arr.len(), 3);
Create an array with repeated values:
let arr = bst_array![42_u32; 5];
assert_eq!(arr.len(), 5);
Create an empty array:
use commonlibsse_ng::re::BSTArray::BSTArray;
let arr: BSTArray<i32> = bst_array![];
assert!(arr.is_empty());
Create an array with a custom allocator:
use stdx::alloc::Global;
let arr = bst_array![with_allocator: Global => 10, 20];
Create a repeated array with a custom allocator:
use stdx::alloc::Global;
let arr = bst_array![with_allocator: Global => 7; 3];
§Note
This macro uses .with_capacity()
and .push()
under the hood.
It does not call resize()
or pre-initialize memory.
The repeated variant ([value; count]
) requires that value
is Clone
,
but cloning is done by the caller expression (i.e., push(value)
).