macro_rules! vec { () => { ... }; ($elem:expr; $n:expr) => { ... }; ($($x:expr),+ $(,)?) => { ... };}Expand description
Creates aVec containing the arguments.
vec! allowsVecs to be defined with the same syntax as array expressions.There are two forms of this macro:
- Create a
Veccontaining a given list of elements:
- Create a
Vecfrom a given element and size:
Note that unlike array expressions this syntax supports all elementswhich implementClone and the number of elements doesn’t have to bea constant.
This will useclone to duplicate an expression, so one should be carefulusing this with types having a nonstandardClone implementation. Forexample,vec![Rc::new(1); 5] will create a vector of five referencesto the same boxed integer value, not five references pointing to independentlyboxed integers.
Also, note thatvec![expr; 0] is allowed, and produces an empty vector.This will still evaluateexpr, however, and immediately drop the resulting value, sobe mindful of side effects.