small_vec

Macro small_vec 

Source
macro_rules! small_vec {
    ($c:expr; $t:ty) => { ... };
    ($c:expr; $t:ty; $($e:expr),+ $(,)?) => { ... };
    ($c:expr;) => { ... };
    ($c:expr; $($e:expr),+ $(,)?) => { ... };
}
Available on crate feature smallvec only.
Expand description

Creates a SmallVec containing the arguments.

small_vec! macro allows creation of a SmallVec using syntax similar to that of the standard array.

§Examples

  1. small_vec![CAPACITY; TYPE] - create an empty SmallVec with given local capacity and element type:
let v = small_vec![3; u64];
assert_eq!(v.capacity(), 3);
assert_eq!(v.is_empty(), true);
assert_eq!(v.is_heap(), false);
  1. small_vec![CAPACITY; TYPE; ELEM+] - create a SmallVec with given local capacity, element type and element values:
let v = small_vec![5; u64; 17];
assert_eq!(v.capacity(), 5);
assert_eq!(v.len(), 1);
assert_eq!(v[0], 17u64);
  1. small_vec![CAPACITY;] - create an empty SmallVec with given local capacity, let the compiler derive the element type:
let mut v = small_vec![3;];
v.push("str");
assert_eq!(v.capacity(), 3);
assert_eq!(v.len(), 1);
assert_eq!(v[0], "str");
  1. small_vec![CAPACITY; ELEM+] - create a SmallVec with given local capacity and elements, let the compiler derive the element type:
let v = small_vec![32; 9, 8, 7];
assert_eq!(v.capacity(), 32);
assert_eq!(v.len(), 3);
assert_eq!(&v[..], &[9, 8, 7]);

§Panics

The macro panics if non-empty small-vector is created and dynamic memory allocation fails. See SmallVec::reserve_exact for more information.