I am learning Rust macros and am confused about the syntax while using vec
. The source code implementing vec!
:
macro_rules! vec {
($elem:expr; $n:expr) => (
$crate::vec::from_elem($elem, $n)
);
($($x:expr),*) => (
<[_]>::into_vec(box [$($x),*])
);
($($x:expr,)*) => (vec![$($x),*])
}
Let's forget the standard way to use it:
let v0 = vec![1, 2, 3];
If we look at the source code, shouldn't we use it like below?
let v1 = vec!(3; 1);
let v2 = vec!(1, 2, 3);
Why do we use []
instead of ()
in v1
and v2
compared to v0
?