[][src]Macro bumpalo::vec

macro_rules! vec {
    (in $bump:expr; $elem:expr; $n:expr) => { ... };
    (in $bump:expr) => { ... };
    (in $bump:expr; $($x:expr),*) => { ... };
    (in $bump:expr; $(, $x:expr,)*) => { ... };
}

Creates a Vec containing the arguments.

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:
use bumpalo::{Bump, vec};

let b = Bump::new();
let v = bumpalo::vec![in &b; 1, 2, 3];
assert_eq!(v[0], 1);
assert_eq!(v[1], 2);
assert_eq!(v[2], 3);
  • Create a Vec from a given element and size:
use bumpalo::{Bump, vec};

let b = Bump::new();
let v = bumpalo::vec![in &b; 1; 3];
assert_eq!(v, [1, 1, 1]);

Note that unlike array expressions this syntax supports all elements which implement Clone and the number of elements doesn't have to be a constant.

This will use clone to duplicate an expression, so one should be careful using this with types having a nonstandard Clone implementation. For example, bumpalo::vec![in ≎ Rc::new(1); 5] will create a vector of five references to the same boxed integer value, not five references pointing to independently boxed integers.