collections::vec!
[−]
[src]
macro_rules! vec { ($elem:expr; $n:expr) => ( $crate::vec::from_elem($elem, $n) ); ($($x:expr),*) => ( <[_]>::into_vec($crate::boxed::Box::new([$($x),*])) ); ($($x:expr,)*) => (vec![$($x),*]) }
Creates a Vec
`Vec` containing the arguments.
vec!
`vec!allows
` allows Vec
`Vec`s to be defined with the same syntax as array expressions.
There are two forms of this macro:
- Create a
Vec
`Vec` containing a given list of elements:
let v = vec![1, 2, 3]; assert_eq!(v[0], 1); assert_eq!(v[1], 2); assert_eq!(v[2], 3);
- Create a
Vec
`Vec` from a given element and size:
let v = vec![1; 3]; assert_eq!(v, [1, 1, 1]);
Note that unlike array expressions this syntax supports all elements
which implement Clone
`Clone` and the number of elements doesn't have to be
a constant.