2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-07-04 22:53:12 +01:00
|
|
|
//! Operations on tuples
|
2012-03-15 18:58:14 -07:00
|
|
|
|
2013-04-03 19:40:27 +13:00
|
|
|
use clone::Clone;
|
2013-01-08 19:37:25 -08:00
|
|
|
use kinds::Copy;
|
2012-12-23 17:41:37 -05:00
|
|
|
use vec;
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2013-05-08 21:11:23 +10:00
|
|
|
#[cfg(not(test))] use cmp::{Eq, Ord};
|
2013-02-28 11:57:33 -05:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
pub use self::getters::*;
|
|
|
|
|
2012-10-07 16:01:01 -07:00
|
|
|
pub trait CopyableTuple<T, U> {
|
2013-03-21 21:20:48 -07:00
|
|
|
fn first(&self) -> T;
|
|
|
|
fn second(&self) -> U;
|
|
|
|
fn swap(&self) -> (U, T);
|
2012-07-17 16:49:54 -07:00
|
|
|
}
|
2012-01-17 19:14:05 +01:00
|
|
|
|
2013-02-20 17:07:17 -08:00
|
|
|
impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
|
2012-07-16 22:32:59 +01:00
|
|
|
|
|
|
|
/// Return the first element of self
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn first(&self) -> T {
|
2013-03-04 22:36:15 -05:00
|
|
|
let (t, _) = *self;
|
2012-08-01 17:30:05 -07:00
|
|
|
return t;
|
2012-07-16 22:32:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the second element of self
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn second(&self) -> U {
|
2013-03-04 22:36:15 -05:00
|
|
|
let (_, u) = *self;
|
2012-08-01 17:30:05 -07:00
|
|
|
return u;
|
2012-07-16 22:32:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the results of swapping the two elements of self
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn swap(&self) -> (U, T) {
|
2013-03-04 22:36:15 -05:00
|
|
|
let (t, u) = *self;
|
2012-08-01 17:30:05 -07:00
|
|
|
return (u, t);
|
2012-07-16 22:32:59 +01:00
|
|
|
}
|
2012-01-17 19:14:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-03 19:40:27 +13:00
|
|
|
impl<T:Clone,U:Clone> Clone for (T, U) {
|
|
|
|
fn clone(&self) -> (T, U) {
|
|
|
|
let (a, b) = match *self {
|
|
|
|
(ref a, ref b) => (a, b)
|
|
|
|
};
|
|
|
|
(a.clone(), b.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 13:11:35 -07:00
|
|
|
pub trait ImmutableTuple<T, U> {
|
|
|
|
fn first_ref<'a>(&'a self) -> &'a T;
|
|
|
|
fn second_ref<'a>(&'a self) -> &'a U;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, U> ImmutableTuple<T, U> for (T, U) {
|
|
|
|
#[inline(always)]
|
|
|
|
fn first_ref<'a>(&'a self) -> &'a T {
|
|
|
|
match *self {
|
|
|
|
(ref t, _) => t,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[inline(always)]
|
|
|
|
fn second_ref<'a>(&'a self) -> &'a U {
|
|
|
|
match *self {
|
|
|
|
(_, ref u) => u,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-28 15:42:13 -07:00
|
|
|
pub trait ExtendedTupleOps<A,B> {
|
2012-09-27 22:20:47 -07:00
|
|
|
fn zip(&self) -> ~[(A, B)];
|
|
|
|
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C];
|
2012-07-17 16:49:54 -07:00
|
|
|
}
|
|
|
|
|
2013-03-25 13:21:04 -07:00
|
|
|
impl<'self,A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&'self [A], &'self [B]) {
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2012-09-27 22:20:47 -07:00
|
|
|
fn zip(&self) -> ~[(A, B)] {
|
|
|
|
match *self {
|
|
|
|
(ref a, ref b) => {
|
|
|
|
vec::zip_slice(*a, *b)
|
|
|
|
}
|
|
|
|
}
|
2012-07-16 17:27:04 -07:00
|
|
|
}
|
|
|
|
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2012-09-27 22:20:47 -07:00
|
|
|
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
|
|
|
|
match *self {
|
|
|
|
(ref a, ref b) => {
|
2013-04-25 01:38:44 -04:00
|
|
|
vec::map_zip(*a, *b, f)
|
2012-09-27 22:20:47 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-16 17:27:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-20 17:07:17 -08:00
|
|
|
impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
|
2012-07-17 16:49:54 -07:00
|
|
|
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2012-09-27 22:20:47 -07:00
|
|
|
fn zip(&self) -> ~[(A, B)] {
|
|
|
|
match *self {
|
|
|
|
(ref a, ref b) => {
|
|
|
|
vec::zip_slice(*a, *b)
|
|
|
|
}
|
|
|
|
}
|
2012-07-16 17:27:04 -07:00
|
|
|
}
|
|
|
|
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2012-09-27 22:20:47 -07:00
|
|
|
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
|
|
|
|
match *self {
|
|
|
|
(ref a, ref b) => {
|
2013-04-25 01:38:44 -04:00
|
|
|
vec::map_zip(*a, *b, f)
|
2012-09-27 22:20:47 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-16 17:27:04 -07:00
|
|
|
}
|
|
|
|
}
|
2012-01-17 19:14:05 +01:00
|
|
|
|
2013-05-08 21:11:23 +10:00
|
|
|
#[cfg(not(test))]
|
2013-03-26 16:08:05 -07:00
|
|
|
impl<A:Eq> Eq for (A,) {
|
|
|
|
#[inline(always)]
|
|
|
|
fn eq(&self, other: &(A,)) -> bool {
|
|
|
|
match (*self) {
|
|
|
|
(ref self_a,) => match other {
|
|
|
|
&(ref other_a,) => {
|
|
|
|
(*self_a).eq(other_a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[inline(always)]
|
|
|
|
fn ne(&self, other: &(A,)) -> bool { !(*self).eq(other) }
|
|
|
|
}
|
|
|
|
|
2013-05-08 21:11:23 +10:00
|
|
|
#[cfg(not(test))]
|
2013-03-26 16:08:05 -07:00
|
|
|
impl<A:Ord> Ord for (A,) {
|
|
|
|
#[inline(always)]
|
|
|
|
fn lt(&self, other: &(A,)) -> bool {
|
|
|
|
match (*self) {
|
|
|
|
(ref self_a,) => {
|
|
|
|
match (*other) {
|
|
|
|
(ref other_a,) => {
|
|
|
|
if (*self_a).lt(other_a) { return true; }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[inline(always)]
|
|
|
|
fn le(&self, other: &(A,)) -> bool { !other.lt(&(*self)) }
|
|
|
|
#[inline(always)]
|
|
|
|
fn ge(&self, other: &(A,)) -> bool { !self.lt(other) }
|
|
|
|
#[inline(always)]
|
|
|
|
fn gt(&self, other: &(A,)) -> bool { other.lt(&(*self)) }
|
|
|
|
}
|
|
|
|
|
2013-05-08 21:11:23 +10:00
|
|
|
#[cfg(not(test))]
|
2013-02-20 17:07:17 -08:00
|
|
|
impl<A:Eq,B:Eq> Eq for (A, B) {
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn eq(&self, other: &(A, B)) -> bool {
|
2012-11-14 18:59:30 -08:00
|
|
|
match (*self) {
|
|
|
|
(ref self_a, ref self_b) => match other {
|
|
|
|
&(ref other_a, ref other_b) => {
|
|
|
|
(*self_a).eq(other_a) && (*self_b).eq(other_b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn ne(&self, other: &(A, B)) -> bool { !(*self).eq(other) }
|
2012-09-19 18:00:26 -07:00
|
|
|
}
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2013-05-08 21:11:23 +10:00
|
|
|
#[cfg(not(test))]
|
2013-02-20 17:07:17 -08:00
|
|
|
impl<A:Ord,B:Ord> Ord for (A, B) {
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn lt(&self, other: &(A, B)) -> bool {
|
2012-11-14 18:59:30 -08:00
|
|
|
match (*self) {
|
|
|
|
(ref self_a, ref self_b) => {
|
|
|
|
match (*other) {
|
|
|
|
(ref other_a, ref other_b) => {
|
|
|
|
if (*self_a).lt(other_a) { return true; }
|
|
|
|
if (*other_a).lt(self_a) { return false; }
|
|
|
|
if (*self_b).lt(other_b) { return true; }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn le(&self, other: &(A, B)) -> bool { !(*other).lt(&(*self)) }
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn ge(&self, other: &(A, B)) -> bool { !(*self).lt(other) }
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn gt(&self, other: &(A, B)) -> bool { (*other).lt(&(*self)) }
|
2012-09-19 18:00:26 -07:00
|
|
|
}
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2013-05-08 21:11:23 +10:00
|
|
|
#[cfg(not(test))]
|
2013-02-20 17:07:17 -08:00
|
|
|
impl<A:Eq,B:Eq,C:Eq> Eq for (A, B, C) {
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn eq(&self, other: &(A, B, C)) -> bool {
|
2012-11-14 18:59:30 -08:00
|
|
|
match (*self) {
|
|
|
|
(ref self_a, ref self_b, ref self_c) => match other {
|
|
|
|
&(ref other_a, ref other_b, ref other_c) => {
|
|
|
|
(*self_a).eq(other_a) && (*self_b).eq(other_b)
|
|
|
|
&& (*self_c).eq(other_c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn ne(&self, other: &(A, B, C)) -> bool { !(*self).eq(other) }
|
2012-09-19 18:00:26 -07:00
|
|
|
}
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2013-05-08 21:11:23 +10:00
|
|
|
#[cfg(not(test))]
|
2013-02-20 17:07:17 -08:00
|
|
|
impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn lt(&self, other: &(A, B, C)) -> bool {
|
2012-11-14 18:59:30 -08:00
|
|
|
match (*self) {
|
|
|
|
(ref self_a, ref self_b, ref self_c) => {
|
|
|
|
match (*other) {
|
|
|
|
(ref other_a, ref other_b, ref other_c) => {
|
|
|
|
if (*self_a).lt(other_a) { return true; }
|
|
|
|
if (*other_a).lt(self_a) { return false; }
|
|
|
|
if (*self_b).lt(other_b) { return true; }
|
|
|
|
if (*other_b).lt(self_b) { return false; }
|
|
|
|
if (*self_c).lt(other_c) { return true; }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn le(&self, other: &(A, B, C)) -> bool { !(*other).lt(&(*self)) }
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn ge(&self, other: &(A, B, C)) -> bool { !(*self).lt(other) }
|
2013-01-13 23:37:30 +09:00
|
|
|
#[inline(always)]
|
2013-03-21 21:20:48 -07:00
|
|
|
fn gt(&self, other: &(A, B, C)) -> bool { (*other).lt(&(*self)) }
|
2012-09-19 18:00:26 -07:00
|
|
|
}
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
// Tuple element getters
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
macro_rules! tuple_getters(
|
|
|
|
($(
|
|
|
|
$name:ident {
|
|
|
|
$(fn $method:ident -> $T:ident { $accessor:pat => $t:expr })+
|
2013-05-18 18:59:16 +10:00
|
|
|
}
|
2013-05-18 19:43:14 +10:00
|
|
|
)+) => (
|
|
|
|
pub mod getters {
|
|
|
|
use kinds::Copy;
|
|
|
|
|
|
|
|
$(pub trait $name<$($T),+> {
|
|
|
|
$(fn $method(&self) -> $T;)+
|
|
|
|
})+
|
|
|
|
|
|
|
|
$(impl<$($T:Copy),+> $name<$($T),+> for ($($T),+) {
|
|
|
|
$(
|
|
|
|
#[inline(always)]
|
|
|
|
fn $method(&self) -> $T {
|
|
|
|
match *self {
|
|
|
|
$accessor => $t
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
}
|
2013-05-18 19:43:14 +10:00
|
|
|
)+
|
|
|
|
})+
|
2013-05-18 18:59:16 +10:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
tuple_getters!(
|
|
|
|
Tuple2 {
|
|
|
|
fn n0 -> A { (a,_) => a }
|
|
|
|
fn n1 -> B { (_,b) => b }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple3 {
|
|
|
|
fn n0 -> A { (a,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c) => c }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple4 {
|
|
|
|
fn n0 -> A { (a,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d) => d }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple5 {
|
|
|
|
fn n0 -> A { (a,_,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d,_) => d }
|
|
|
|
fn n4 -> E { (_,_,_,_,e) => e }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple6 {
|
|
|
|
fn n0 -> A { (a,_,_,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_,_,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d,_,_) => d }
|
|
|
|
fn n4 -> E { (_,_,_,_,e,_) => e }
|
|
|
|
fn n5 -> F { (_,_,_,_,_,f) => f }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple7 {
|
|
|
|
fn n0 -> A { (a,_,_,_,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_,_,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_,_,_,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d,_,_,_) => d }
|
|
|
|
fn n4 -> E { (_,_,_,_,e,_,_) => e }
|
|
|
|
fn n5 -> F { (_,_,_,_,_,f,_) => f }
|
|
|
|
fn n6 -> G { (_,_,_,_,_,_,g) => g }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple8 {
|
|
|
|
fn n0 -> A { (a,_,_,_,_,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_,_,_,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_,_,_,_,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d,_,_,_,_) => d }
|
|
|
|
fn n4 -> E { (_,_,_,_,e,_,_,_) => e }
|
|
|
|
fn n5 -> F { (_,_,_,_,_,f,_,_) => f }
|
|
|
|
fn n6 -> G { (_,_,_,_,_,_,g,_) => g }
|
|
|
|
fn n7 -> H { (_,_,_,_,_,_,_,h) => h }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple9 {
|
|
|
|
fn n0 -> A { (a,_,_,_,_,_,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_,_,_,_,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_,_,_,_,_,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d,_,_,_,_,_) => d }
|
|
|
|
fn n4 -> E { (_,_,_,_,e,_,_,_,_) => e }
|
|
|
|
fn n5 -> F { (_,_,_,_,_,f,_,_,_) => f }
|
|
|
|
fn n6 -> G { (_,_,_,_,_,_,g,_,_) => g }
|
|
|
|
fn n7 -> H { (_,_,_,_,_,_,_,h,_) => h }
|
|
|
|
fn n8 -> I { (_,_,_,_,_,_,_,_,i) => i }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple10 {
|
|
|
|
fn n0 -> A { (a,_,_,_,_,_,_,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_,_,_,_,_,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_,_,_,_,_,_,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d,_,_,_,_,_,_) => d }
|
|
|
|
fn n4 -> E { (_,_,_,_,e,_,_,_,_,_) => e }
|
|
|
|
fn n5 -> F { (_,_,_,_,_,f,_,_,_,_) => f }
|
|
|
|
fn n6 -> G { (_,_,_,_,_,_,g,_,_,_) => g }
|
|
|
|
fn n7 -> H { (_,_,_,_,_,_,_,h,_,_) => h }
|
|
|
|
fn n8 -> I { (_,_,_,_,_,_,_,_,i,_) => i }
|
|
|
|
fn n9 -> J { (_,_,_,_,_,_,_,_,_,j) => j }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple11 {
|
|
|
|
fn n0 -> A { (a,_,_,_,_,_,_,_,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_,_,_,_,_,_,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_,_,_,_,_,_,_,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d,_,_,_,_,_,_,_) => d }
|
|
|
|
fn n4 -> E { (_,_,_,_,e,_,_,_,_,_,_) => e }
|
|
|
|
fn n5 -> F { (_,_,_,_,_,f,_,_,_,_,_) => f }
|
|
|
|
fn n6 -> G { (_,_,_,_,_,_,g,_,_,_,_) => g }
|
|
|
|
fn n7 -> H { (_,_,_,_,_,_,_,h,_,_,_) => h }
|
|
|
|
fn n8 -> I { (_,_,_,_,_,_,_,_,i,_,_) => i }
|
|
|
|
fn n9 -> J { (_,_,_,_,_,_,_,_,_,j,_) => j }
|
|
|
|
fn n10 -> K { (_,_,_,_,_,_,_,_,_,_,k) => k }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-18 19:43:14 +10:00
|
|
|
Tuple12 {
|
|
|
|
fn n0 -> A { (a,_,_,_,_,_,_,_,_,_,_,_) => a }
|
|
|
|
fn n1 -> B { (_,b,_,_,_,_,_,_,_,_,_,_) => b }
|
|
|
|
fn n2 -> C { (_,_,c,_,_,_,_,_,_,_,_,_) => c }
|
|
|
|
fn n3 -> D { (_,_,_,d,_,_,_,_,_,_,_,_) => d }
|
|
|
|
fn n4 -> E { (_,_,_,_,e,_,_,_,_,_,_,_) => e }
|
|
|
|
fn n5 -> F { (_,_,_,_,_,f,_,_,_,_,_,_) => f }
|
|
|
|
fn n6 -> G { (_,_,_,_,_,_,g,_,_,_,_,_) => g }
|
|
|
|
fn n7 -> H { (_,_,_,_,_,_,_,h,_,_,_,_) => h }
|
|
|
|
fn n8 -> I { (_,_,_,_,_,_,_,_,i,_,_,_) => i }
|
|
|
|
fn n9 -> J { (_,_,_,_,_,_,_,_,_,j,_,_) => j }
|
|
|
|
fn n10 -> K { (_,_,_,_,_,_,_,_,_,_,k,_) => k }
|
|
|
|
fn n11 -> L { (_,_,_,_,_,_,_,_,_,_,_,l) => l }
|
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
)
|
|
|
|
|
2012-10-07 16:01:01 -07:00
|
|
|
#[test]
|
|
|
|
fn test_tuple_ref() {
|
2012-10-07 20:30:17 -07:00
|
|
|
let x = (~"foo", ~"bar");
|
2013-05-18 19:10:49 +10:00
|
|
|
assert_eq!(x.first_ref(), &~"foo");
|
|
|
|
assert_eq!(x.second_ref(), &~"bar");
|
2012-10-07 16:01:01 -07:00
|
|
|
}
|
|
|
|
|
2012-01-17 19:14:05 +01:00
|
|
|
#[test]
|
2012-09-02 16:34:20 -07:00
|
|
|
#[allow(non_implicitly_copyable_typarams)]
|
2012-01-17 19:14:05 +01:00
|
|
|
fn test_tuple() {
|
2013-05-18 19:10:49 +10:00
|
|
|
assert_eq!((948, 4039.48).first(), 948);
|
|
|
|
assert_eq!((34.5, ~"foo").second(), ~"foo");
|
|
|
|
assert_eq!(('a', 2).swap(), (2, 'a'));
|
2012-01-17 19:14:05 +01:00
|
|
|
}
|
|
|
|
|
2013-04-03 19:40:27 +13:00
|
|
|
#[test]
|
|
|
|
fn test_clone() {
|
|
|
|
let a = (1, ~"2");
|
|
|
|
let b = a.clone();
|
2013-05-18 19:10:49 +10:00
|
|
|
assert_eq!(a.first(), b.first());
|
|
|
|
assert_eq!(a.second(), b.second());
|
2013-04-03 19:40:27 +13:00
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_n_tuple() {
|
|
|
|
let t = (0u8, 1u16, 2u32, 3u64, 4u, 5i8, 6i16, 7i32, 8i64, 9i, 10f32, 11f64);
|
2013-05-18 19:10:12 +10:00
|
|
|
assert_eq!(t.n0(), 0u8);
|
|
|
|
assert_eq!(t.n1(), 1u16);
|
|
|
|
assert_eq!(t.n2(), 2u32);
|
|
|
|
assert_eq!(t.n3(), 3u64);
|
|
|
|
assert_eq!(t.n4(), 4u);
|
|
|
|
assert_eq!(t.n5(), 5i8);
|
|
|
|
assert_eq!(t.n6(), 6i16);
|
|
|
|
assert_eq!(t.n7(), 7i32);
|
|
|
|
assert_eq!(t.n8(), 8i64);
|
|
|
|
assert_eq!(t.n9(), 9i);
|
|
|
|
assert_eq!(t.n10(), 10f32);
|
|
|
|
assert_eq!(t.n11(), 11f64);
|
2013-05-18 18:59:16 +10:00
|
|
|
}
|