Macro stack_buf::stack_vec [−][src]
Creates a StackVec containing the arguments.
stack_vec! allows StackVecs to be defined with the same syntax as array expressions.
There are two forms of this macro:
- Creates a empty
StackVec:
use stack_buf::{StackVec, stack_vec}; let vec: StackVec<i32, 8> = stack_vec![]; assert!(vec.is_empty());
- Creates a
StackVeccontaining a given list of elements:
use stack_buf::{StackVec, stack_vec}; let vec: StackVec<_, 128> = stack_vec![1, 2, 3]; assert_eq!(vec[0], 1); assert_eq!(vec[1], 2); assert_eq!(vec[2], 3);
- Creates a
StackVecfrom a given element and size:
use stack_buf::{StackVec, stack_vec}; let v: StackVec<_, 0x8000> = stack_vec![1; 3]; assert_eq!(v.as_slice(), [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, stack_vec![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.