macro_rules! array_vec {
    ($c:expr; $t:ty) => { ... };
    ($c:expr; $t:ty; $($e:expr),+ $(,)?) => { ... };
    ($c:expr;) => { ... };
    ($c:expr; $($e:expr),+ $(,)?) => { ... };
}
This is supported on crate feature arrayvec only.
Expand description

Creates an ArrayVec containing the arguments.

array_vec! macro allows creation of an ArrayVec using syntax similar to that of the standard array.

Examples

  1. array_vec![CAPACITY; TYPE] - create an empty ArrayVec with given capacity and type:
let a = array_vec![3; u64];
assert_eq!(a.capacity(), 3);
assert_eq!(a.len(), 0);
  1. array_vec![CAPACITY; TYPE; ELEM+] - create an ArrayVec with given capacity, type and elements:
let a = array_vec![5; u64; 17];
assert_eq!(a.capacity(), 5);
assert_eq!(a.len(), 1);
assert_eq!(a[0], 17u64);
  1. array_vec![CAPACITY;] - create an empty ArrayVec with given capacity, let the compiler derive the type:
let mut a = array_vec![3;];
a.push("str");
assert_eq!(a.capacity(), 3);
assert_eq!(a.len(), 1);
assert_eq!(a[0], "str");
  1. array_vec![CAPACITY; ELEM+] - create an ArrayVec with given capacity and elements, let the compiler derive the type:
let a = array_vec![32; 9, 8, 7];
assert_eq!(a.capacity(), 32);
assert_eq!(a.len(), 3);
assert_eq!(&a[..], &[9, 8, 7]);
  1. array_vec! panics if the number of elements exceeds the requested capacity:
array_vec![0; u64; 1];

Panics

The macro panics if the number of elements exceeds the requested capacity.