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.
This commit is contained in:
parent
bb2168c525
commit
eb9684ee19
1 changed files with 22 additions and 8 deletions
|
@ -8,22 +8,36 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
/*!
|
//! Implementations of things like `Eq` for fixed-length arrays
|
||||||
* Implementations of things like `Eq` for fixed-length arrays
|
//! up to a certain length. Eventually we should able to generalize
|
||||||
* up to a certain length. Eventually we should able to generalize
|
//! to all lengths.
|
||||||
* to all lengths.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#![stable]
|
|
||||||
#![experimental] // not yet reviewed
|
#![experimental] // not yet reviewed
|
||||||
|
|
||||||
use cmp::*;
|
use clone::Clone;
|
||||||
use option::{Option};
|
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 for implementing n-ary tuple functions and operations
|
||||||
macro_rules! array_impls {
|
macro_rules! array_impls {
|
||||||
($($N:expr)+) => {
|
($($N:expr)+) => {
|
||||||
$(
|
$(
|
||||||
|
#[unstable = "waiting for Clone to stabilize"]
|
||||||
|
impl<T:Copy> Clone for [T, ..$N] {
|
||||||
|
fn clone(&self) -> [T, ..$N] {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unstable = "waiting for Show to stabilize"]
|
||||||
|
impl<T:fmt::Show> 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"]
|
#[unstable = "waiting for PartialEq to stabilize"]
|
||||||
impl<T:PartialEq> PartialEq for [T, ..$N] {
|
impl<T:PartialEq> PartialEq for [T, ..$N] {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue