Skip to content

Commit 02a5e16

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 191330 b: refs/heads/try c: 633c593 h: refs/heads/master v: v3
1 parent 7d26e95 commit 02a5e16

File tree

26 files changed

+944
-1
lines changed

26 files changed

+944
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 809a554fca2d0ebc2ba50077016fe282a4064752
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9
5-
refs/heads/try: 5b118f5ecde796ad62fa349a045d7ad8129b711c
5+
refs/heads/try: 633c593bc3f9787decfaf943cdc5659f132ade50
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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)