Skip to content

Commit

Permalink
impl<T> [T]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Mar 17, 2015
1 parent 5b118f5 commit 633c593
Show file tree
Hide file tree
Showing 25 changed files with 943 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/libcollections/macros.rs
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

#[cfg(not(stage0))]
/// Creates a `Vec` containing the arguments.
///
/// `vec!` allows `Vec`s to be defined with the same syntax as array expressions.
/// There are two forms of this macro:
///
/// - Create a `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` 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` and the number of elements doesn't have to be
/// a constant.
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
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),*])
}

/// Use the syntax described in `std::fmt` to create a value of type `String`.
/// See `std::fmt` for more information.
///
Expand Down

0 comments on commit 633c593

Please sign in to comment.