Merge pull request #73 from b52/master
Implement Rand for arrays with n <= 32
diff --git a/.travis.yml b/.travis.yml
index c4ca38d..5c1cc7c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,7 @@
language: rust
rust:
- 1.0.0
+ - stable
- beta
- nightly
sudo: false
diff --git a/rand_macros/src/lib.rs b/rand_macros/src/lib.rs
index c8dd99b..6ce05c1 100644
--- a/rand_macros/src/lib.rs
+++ b/rand_macros/src/lib.rs
@@ -45,6 +45,7 @@
path: Path::new(vec!("rand", "Rand")),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
+ is_unsafe: false,
methods: vec!(
MethodDef {
name: "rand",
diff --git a/src/rand_impls.rs b/src/rand_impls.rs
index 0303a9c..5a7e3de 100644
--- a/src/rand_impls.rs
+++ b/src/rand_impls.rs
@@ -199,6 +199,26 @@
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K}
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K, L}
+macro_rules! array_impl {
+ {$n:expr, $t:ident, $($ts:ident,)*} => {
+ array_impl!{($n - 1), $($ts,)*}
+
+ impl<T> Rand for [T; $n] where T: Rand {
+ #[inline]
+ fn rand<R: Rng>(_rng: &mut R) -> [T; $n] {
+ [_rng.gen::<$t>(), $(_rng.gen::<$ts>()),*]
+ }
+ }
+ };
+ {$n:expr,} => {
+ impl<T> Rand for [T; $n] {
+ fn rand<R: Rng>(_rng: &mut R) -> [T; $n] { [] }
+ }
+ };
+}
+
+array_impl!{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,}
+
impl<T:Rand> Rand for Option<T> {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> Option<T> {