Skip to content

Commit 633c593

Browse files
author
Jorge Aparicio
committed
impl<T> [T]
1 parent 5b118f5 commit 633c593

File tree

25 files changed

+943
-0
lines changed

25 files changed

+943
-0
lines changed

src/libcollections/macros.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[cfg(stage0)]
1112
/// Creates a `Vec` containing the arguments.
1213
///
1314
/// `vec!` allows `Vec`s to be defined with the same syntax as array expressions.
@@ -45,6 +46,43 @@ macro_rules! vec {
4546
($($x:expr,)*) => (vec![$($x),*])
4647
}
4748

49+
#[cfg(not(stage0))]
50+
/// Creates a `Vec` containing the arguments.
51+
///
52+
/// `vec!` allows `Vec`s to be defined with the same syntax as array expressions.
53+
/// There are two forms of this macro:
54+
///
55+
/// - Create a `Vec` containing a given list of elements:
56+
///
57+
/// ```
58+
/// let v = vec![1, 2, 3];
59+
/// assert_eq!(v[0], 1);
60+
/// assert_eq!(v[1], 2);
61+
/// assert_eq!(v[2], 3);
62+
/// ```
63+
///
64+
/// - Create a `Vec` from a given element and size:
65+
///
66+
/// ```
67+
/// let v = vec![1; 3];
68+
/// assert_eq!(v, [1, 1, 1]);
69+
/// ```
70+
///
71+
/// Note that unlike array expressions this syntax supports all elements
72+
/// which implement `Clone` and the number of elements doesn't have to be
73+
/// a constant.
74+
#[macro_export]
75+
#[stable(feature = "rust1", since = "1.0.0")]
76+
macro_rules! vec {
77+
($elem:expr; $n:expr) => (
78+
$crate::vec::from_elem($elem, $n)
79+
);
80+
($($x:expr),*) => (
81+
<[_]>::into_vec($crate::boxed::Box::new([$($x),*]))
82+
);
83+
($($x:expr,)*) => (vec![$($x),*])
84+
}
85+
4886
/// Use the syntax described in `std::fmt` to create a value of type `String`.
4987
/// See `std::fmt` for more information.
5088
///

0 commit comments

Comments
 (0)