Macro boxcar::vec

source ·
macro_rules! vec {
    () => { ... };
    ($elem:expr; $n:expr) => { ... };
    ($($x:expr),+ $(,)?) => { ... };
}
Expand description

Creates a Vec containing the given elements.

vec! allows Vecs to be defined with the same syntax as array expressions. There are two forms of this macro:

  • Create a Vec containing a given list of elements:
let vec = vec![1, 2, 3];
assert_eq!(vec[0], 1);
assert_eq!(vec[1], 2);
assert_eq!(vec[2], 3);
  • Create a Vec from a given element and size:
let vec = vec![1; 3];
assert_eq!(vec, [1, 1, 1]);