summary refs log tree commit diff
path: root/src/libcore/array.rs
diff options
context:
space:
mode:
authorWithout Boats <woboats@gmail.com>2015-08-14 10:11:19 -0700
committerWithout Boats <woboats@gmail.com>2015-08-14 10:11:19 -0700
commit975a8ed312bbe262171b4c950c52cf992293bd55 (patch)
treeccb741adaf11f44f57a193fb88170c045270f23c /src/libcore/array.rs
parentc1e865c9df3c6928525025e410fc3d165fb97c85 (diff)
downloadrust-975a8ed312bbe262171b4c950c52cf992293bd55.tar.gz
rust-975a8ed312bbe262171b4c950c52cf992293bd55.zip
Implemented Default for arrays up to [T; 32].
Diffstat (limited to 'src/libcore/array.rs')
-rw-r--r--src/libcore/array.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libcore/array.rs b/src/libcore/array.rs
index cfe22b89178..d8b363b8cf7 100644
--- a/src/libcore/array.rs
+++ b/src/libcore/array.rs
@@ -21,6 +21,7 @@
 use clone::Clone;
 use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
 use convert::{AsRef, AsMut};
+use default::Default;
 use fmt;
 use hash::{Hash, self};
 use iter::IntoIterator;
@@ -161,3 +162,26 @@ array_impls! {
     20 21 22 23 24 25 26 27 28 29
     30 31 32
 }
+
+// The Default impls cannot be generated using the array_impls! macro because
+// they require array literals.
+
+macro_rules! array_impl_default {
+    {$n:expr, $t:ident $($ts:ident)*} => {
+        #[stable(since = "1.4.0", feature = "array_default")]
+        impl<T> Default for [T; $n] where T: Default {
+            fn default() -> [T; $n] {
+                [$t::default(), $($ts::default()),*]
+            }
+        }
+        array_impl_default!{($n - 1), $($ts)*}
+    };
+    {$n:expr,} => {
+        #[stable(since = "1.4.0", feature = "array_default")]
+        impl<T> Default for [T; $n] {
+            fn default() -> [T; $n] { [] }
+        }
+    };
+}
+
+array_impl_default!{32, T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T}