From eb9684ee19e1d79999b9809704fbffe072332e7b Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 14 Nov 2014 12:37:59 +0100 Subject: [PATCH] Add `Show` and `Clone` trait to arrays Due to not being able to parametrize over array sizes, `Clone` is only implemented for element types that are `Copy`able. --- src/libcore/array.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 829605ce7cc..60765e82cb4 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -8,22 +8,36 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/*! - * Implementations of things like `Eq` for fixed-length arrays - * up to a certain length. Eventually we should able to generalize - * to all lengths. - */ +//! Implementations of things like `Eq` for fixed-length arrays +//! up to a certain length. Eventually we should able to generalize +//! to all lengths. -#![stable] #![experimental] // not yet reviewed -use cmp::*; -use option::{Option}; +use clone::Clone; +use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; +use fmt; +use kinds::Copy; +use option::Option; // macro for implementing n-ary tuple functions and operations macro_rules! array_impls { ($($N:expr)+) => { $( + #[unstable = "waiting for Clone to stabilize"] + impl Clone for [T, ..$N] { + fn clone(&self) -> [T, ..$N] { + *self + } + } + + #[unstable = "waiting for Show to stabilize"] + impl fmt::Show for [T, ..$N] { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Show::fmt(&self[], f) + } + } + #[unstable = "waiting for PartialEq to stabilize"] impl PartialEq for [T, ..$N] { #[inline]