2012-12-03 18:48:01 -06: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 16:53:12 -05:00
|
|
|
//! Operations on tuples
|
2012-03-15 20:58:14 -05:00
|
|
|
|
2013-05-28 16:35:52 -05:00
|
|
|
#[allow(missing_doc)];
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
use clone::Clone;
|
2013-11-29 08:52:38 -06:00
|
|
|
#[cfg(not(test))] use cmp::*;
|
|
|
|
#[cfg(not(test))] use default::Default;
|
2013-05-18 04:43:14 -05:00
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
/// Method extensions to pairs where both types satisfy the `Clone` bound
|
2012-10-07 18:01:01 -05:00
|
|
|
pub trait CopyableTuple<T, U> {
|
2013-05-28 16:35:52 -05:00
|
|
|
/// Return the first element of self
|
2013-03-21 23:20:48 -05:00
|
|
|
fn first(&self) -> T;
|
2013-05-28 16:35:52 -05:00
|
|
|
/// Return the second element of self
|
2013-03-21 23:20:48 -05:00
|
|
|
fn second(&self) -> U;
|
2013-05-28 16:35:52 -05:00
|
|
|
/// Return the results of swapping the two elements of self
|
2013-03-21 23:20:48 -05:00
|
|
|
fn swap(&self) -> (U, T);
|
2012-07-17 18:49:54 -05:00
|
|
|
}
|
2012-01-17 12:14:05 -06:00
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
impl<T:Clone,U:Clone> CopyableTuple<T, U> for (T, U) {
|
2012-07-16 16:32:59 -05:00
|
|
|
/// Return the first element of self
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-03-21 23:20:48 -05:00
|
|
|
fn first(&self) -> T {
|
2013-05-18 07:18:23 -05:00
|
|
|
match *self {
|
2013-07-02 14:47:32 -05:00
|
|
|
(ref t, _) => (*t).clone(),
|
2013-05-18 07:18:23 -05:00
|
|
|
}
|
2012-07-16 16:32:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the second element of self
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-03-21 23:20:48 -05:00
|
|
|
fn second(&self) -> U {
|
2013-05-18 07:18:23 -05:00
|
|
|
match *self {
|
2013-07-02 14:47:32 -05:00
|
|
|
(_, ref u) => (*u).clone(),
|
2013-05-18 07:18:23 -05:00
|
|
|
}
|
2012-07-16 16:32:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the results of swapping the two elements of self
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-03-21 23:20:48 -05:00
|
|
|
fn swap(&self) -> (U, T) {
|
2013-07-02 14:47:32 -05:00
|
|
|
match (*self).clone() {
|
2013-05-18 07:18:23 -05:00
|
|
|
(t, u) => (u, t),
|
|
|
|
}
|
2012-07-16 16:32:59 -05:00
|
|
|
}
|
2013-04-03 01:40:27 -05:00
|
|
|
}
|
|
|
|
|
2013-05-28 16:35:52 -05:00
|
|
|
/// Method extensions for pairs where the types don't necessarily satisfy the
|
2013-07-02 14:47:32 -05:00
|
|
|
/// `Clone` bound
|
2013-04-10 15:11:35 -05:00
|
|
|
pub trait ImmutableTuple<T, U> {
|
2013-05-28 16:35:52 -05:00
|
|
|
/// Return a reference to the first element of self
|
2013-04-10 15:11:35 -05:00
|
|
|
fn first_ref<'a>(&'a self) -> &'a T;
|
2013-05-28 16:35:52 -05:00
|
|
|
/// Return a reference to the second element of self
|
2013-04-10 15:11:35 -05:00
|
|
|
fn second_ref<'a>(&'a self) -> &'a U;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, U> ImmutableTuple<T, U> for (T, U) {
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-04-10 15:11:35 -05:00
|
|
|
fn first_ref<'a>(&'a self) -> &'a T {
|
|
|
|
match *self {
|
|
|
|
(ref t, _) => t,
|
|
|
|
}
|
|
|
|
}
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-04-10 15:11:35 -05:00
|
|
|
fn second_ref<'a>(&'a self) -> &'a U {
|
|
|
|
match *self {
|
|
|
|
(_, ref u) => u,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-18 06:38:06 -05:00
|
|
|
// macro for implementing n-ary tuple functions and operations
|
|
|
|
|
2013-05-19 03:51:14 -05:00
|
|
|
macro_rules! tuple_impls {
|
2013-05-18 06:38:06 -05:00
|
|
|
($(
|
2013-09-25 04:00:08 -05:00
|
|
|
($move_trait:ident, $immutable_trait:ident) {
|
2013-05-18 07:46:02 -05:00
|
|
|
$(($get_fn:ident, $get_ref_fn:ident) -> $T:ident {
|
2013-09-25 04:00:08 -05:00
|
|
|
$move_pattern:pat, $ref_pattern:pat => $ret:expr
|
2013-05-18 07:46:02 -05:00
|
|
|
})+
|
2013-03-26 18:08:05 -05:00
|
|
|
}
|
2013-05-19 03:51:14 -05:00
|
|
|
)+) => {
|
2013-11-29 08:52:38 -06:00
|
|
|
$(
|
|
|
|
pub trait $move_trait<$($T),+> {
|
|
|
|
$(fn $get_fn(self) -> $T;)+
|
|
|
|
}
|
2013-05-18 07:46:02 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) {
|
|
|
|
$(
|
|
|
|
#[inline]
|
|
|
|
fn $get_fn(self) -> $T {
|
|
|
|
let $move_pattern = self;
|
|
|
|
$ret
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
2013-03-26 18:08:05 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
pub trait $immutable_trait<$($T),+> {
|
|
|
|
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
|
|
|
|
}
|
2012-08-27 18:26:35 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
|
|
|
|
$(
|
|
|
|
#[inline]
|
|
|
|
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
|
|
|
|
let $ref_pattern = *self;
|
|
|
|
$ret
|
2012-11-14 20:59:30 -06:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<$($T:Clone),+> Clone for ($($T,)+) {
|
|
|
|
fn clone(&self) -> ($($T,)+) {
|
|
|
|
($(self.$get_ref_fn().clone(),)+)
|
2012-11-14 20:59:30 -06:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2012-08-27 18:26:35 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:Eq),+> Eq for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &($($T,)+)) -> bool {
|
|
|
|
$(*self.$get_ref_fn() == *other.$get_ref_fn())&&+
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &($($T,)+)) -> bool {
|
|
|
|
$(*self.$get_ref_fn() != *other.$get_ref_fn())||+
|
2012-11-14 20:59:30 -06:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2012-08-27 18:26:35 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn equals(&self, other: &($($T,)+)) -> bool {
|
|
|
|
$(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2013-05-19 03:51:14 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:Ord + Eq),+> Ord for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn lt(&self, other: &($($T,)+)) -> bool {
|
|
|
|
lexical_ord!(lt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn le(&self, other: &($($T,)+)) -> bool {
|
|
|
|
lexical_ord!(le, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ge(&self, other: &($($T,)+)) -> bool {
|
|
|
|
lexical_ord!(ge, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
|
2013-05-18 06:38:06 -05:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
#[inline]
|
|
|
|
fn gt(&self, other: &($($T,)+)) -> bool {
|
|
|
|
lexical_ord!(gt, $(self.$get_ref_fn(), other.$get_ref_fn()),+)
|
|
|
|
}
|
|
|
|
}
|
2013-05-19 03:51:14 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn cmp(&self, other: &($($T,)+)) -> Ordering {
|
|
|
|
lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+)
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2013-06-14 20:27:52 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:Default),+> Default for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn default() -> ($($T,)+) {
|
|
|
|
($({ let x: $T = Default::default(); x},)+)
|
2013-09-11 23:49:25 -05:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
|
|
|
)+
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:07:22 -05:00
|
|
|
// Constructs an expression that performs a lexical ordering using method $rel.
|
|
|
|
// The values are interleaved, so the macro invocation for
|
|
|
|
// `(a1, a2, a3) < (b1, b2, b3)` would be `lexical_ord!(lt, a1, b1, a2, b2,
|
2013-05-19 03:51:14 -05:00
|
|
|
// a3, b3)` (and similarly for `lexical_cmp`)
|
2013-08-08 15:07:22 -05:00
|
|
|
macro_rules! lexical_ord {
|
|
|
|
($rel: ident, $a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
|
|
|
if *$a != *$b { lexical_ord!($rel, $a, $b) }
|
|
|
|
else { lexical_ord!($rel, $($rest_a, $rest_b),+) }
|
2013-05-19 03:51:14 -05:00
|
|
|
};
|
2013-08-08 15:07:22 -05:00
|
|
|
($rel: ident, $a:expr, $b:expr) => { (*$a) . $rel ($b) };
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! lexical_cmp {
|
|
|
|
($a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
|
|
|
match ($a).cmp($b) {
|
|
|
|
Equal => lexical_cmp!($($rest_a, $rest_b),+),
|
|
|
|
ordering => ordering
|
|
|
|
}
|
|
|
|
};
|
|
|
|
($a:expr, $b:expr) => { ($a).cmp($b) };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tuple_impls! {
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple1, ImmutableTuple1) {
|
|
|
|
(n0, n0_ref) -> A { (a,), (ref a,) => a }
|
2013-08-08 15:07:21 -05:00
|
|
|
}
|
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple2, ImmutableTuple2) {
|
|
|
|
(n0, n0_ref) -> A { (a,_), (ref a,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b), (_,ref b) => b }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple3, ImmutableTuple3) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_), (ref a,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_), (_,ref b,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c), (_,_,ref c) => c }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple4, ImmutableTuple4) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_), (ref a,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_), (_,ref b,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_), (_,_,ref c,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d), (_,_,_,ref d) => d }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple5, ImmutableTuple5) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_,_), (ref a,_,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_,_), (_,ref b,_,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_,_), (_,_,ref c,_,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d,_), (_,_,_,ref d,_) => d }
|
|
|
|
(n4, n4_ref) -> E { (_,_,_,_,e), (_,_,_,_,ref e) => e }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple6, ImmutableTuple6) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_,_,_), (ref a,_,_,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_,_,_), (_,ref b,_,_,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_,_,_), (_,_,ref c,_,_,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d,_,_), (_,_,_,ref d,_,_) => d }
|
|
|
|
(n4, n4_ref) -> E { (_,_,_,_,e,_), (_,_,_,_,ref e,_) => e }
|
|
|
|
(n5, n5_ref) -> F { (_,_,_,_,_,f), (_,_,_,_,_,ref f) => f }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple7, ImmutableTuple7) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_,_,_,_), (ref a,_,_,_,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_,_,_,_), (_,ref b,_,_,_,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_,_,_,_), (_,_,ref c,_,_,_,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d,_,_,_), (_,_,_,ref d,_,_,_) => d }
|
|
|
|
(n4, n4_ref) -> E { (_,_,_,_,e,_,_), (_,_,_,_,ref e,_,_) => e }
|
|
|
|
(n5, n5_ref) -> F { (_,_,_,_,_,f,_), (_,_,_,_,_,ref f,_) => f }
|
|
|
|
(n6, n6_ref) -> G { (_,_,_,_,_,_,g), (_,_,_,_,_,_,ref g) => g }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple8, ImmutableTuple8) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_), (_,_,ref c,_,_,_,_,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d,_,_,_,_), (_,_,_,ref d,_,_,_,_) => d }
|
|
|
|
(n4, n4_ref) -> E { (_,_,_,_,e,_,_,_), (_,_,_,_,ref e,_,_,_) => e }
|
|
|
|
(n5, n5_ref) -> F { (_,_,_,_,_,f,_,_), (_,_,_,_,_,ref f,_,_) => f }
|
|
|
|
(n6, n6_ref) -> G { (_,_,_,_,_,_,g,_), (_,_,_,_,_,_,ref g,_) => g }
|
|
|
|
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h), (_,_,_,_,_,_,_,ref h) => h }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple9, ImmutableTuple9) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d,_,_,_,_,_), (_,_,_,ref d,_,_,_,_,_) => d }
|
|
|
|
(n4, n4_ref) -> E { (_,_,_,_,e,_,_,_,_), (_,_,_,_,ref e,_,_,_,_) => e }
|
|
|
|
(n5, n5_ref) -> F { (_,_,_,_,_,f,_,_,_), (_,_,_,_,_,ref f,_,_,_) => f }
|
|
|
|
(n6, n6_ref) -> G { (_,_,_,_,_,_,g,_,_), (_,_,_,_,_,_,ref g,_,_) => g }
|
|
|
|
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_), (_,_,_,_,_,_,_,ref h,_) => h }
|
|
|
|
(n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i), (_,_,_,_,_,_,_,_,ref i) => i }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple10, ImmutableTuple10) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d,_,_,_,_,_,_), (_,_,_,ref d,_,_,_,_,_,_) => d }
|
|
|
|
(n4, n4_ref) -> E { (_,_,_,_,e,_,_,_,_,_), (_,_,_,_,ref e,_,_,_,_,_) => e }
|
|
|
|
(n5, n5_ref) -> F { (_,_,_,_,_,f,_,_,_,_), (_,_,_,_,_,ref f,_,_,_,_) => f }
|
|
|
|
(n6, n6_ref) -> G { (_,_,_,_,_,_,g,_,_,_), (_,_,_,_,_,_,ref g,_,_,_) => g }
|
|
|
|
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_,_), (_,_,_,_,_,_,_,ref h,_,_) => h }
|
|
|
|
(n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_), (_,_,_,_,_,_,_,_,ref i,_) => i }
|
|
|
|
(n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j), (_,_,_,_,_,_,_,_,_,ref j) => j }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple11, ImmutableTuple11) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d,_,_,_,_,_,_,_), (_,_,_,ref d,_,_,_,_,_,_,_) => d }
|
|
|
|
(n4, n4_ref) -> E { (_,_,_,_,e,_,_,_,_,_,_), (_,_,_,_,ref e,_,_,_,_,_,_) => e }
|
|
|
|
(n5, n5_ref) -> F { (_,_,_,_,_,f,_,_,_,_,_), (_,_,_,_,_,ref f,_,_,_,_,_) => f }
|
|
|
|
(n6, n6_ref) -> G { (_,_,_,_,_,_,g,_,_,_,_), (_,_,_,_,_,_,ref g,_,_,_,_) => g }
|
|
|
|
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_,_,_), (_,_,_,_,_,_,_,ref h,_,_,_) => h }
|
|
|
|
(n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_,_), (_,_,_,_,_,_,_,_,ref i,_,_) => i }
|
|
|
|
(n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j,_), (_,_,_,_,_,_,_,_,_,ref j,_) => j }
|
|
|
|
(n10, n10_ref) -> K { (_,_,_,_,_,_,_,_,_,_,k), (_,_,_,_,_,_,_,_,_,_,ref k) => k }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-09-25 04:00:08 -05:00
|
|
|
(Tuple12, ImmutableTuple12) {
|
|
|
|
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_,_) => a }
|
|
|
|
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_,_) => b }
|
|
|
|
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_,_) => c }
|
|
|
|
(n3, n3_ref) -> D { (_,_,_,d,_,_,_,_,_,_,_,_), (_,_,_,ref d,_,_,_,_,_,_,_,_) => d }
|
|
|
|
(n4, n4_ref) -> E { (_,_,_,_,e,_,_,_,_,_,_,_), (_,_,_,_,ref e,_,_,_,_,_,_,_) => e }
|
|
|
|
(n5, n5_ref) -> F { (_,_,_,_,_,f,_,_,_,_,_,_), (_,_,_,_,_,ref f,_,_,_,_,_,_) => f }
|
|
|
|
(n6, n6_ref) -> G { (_,_,_,_,_,_,g,_,_,_,_,_), (_,_,_,_,_,_,ref g,_,_,_,_,_) => g }
|
|
|
|
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_,_,_,_), (_,_,_,_,_,_,_,ref h,_,_,_,_) => h }
|
|
|
|
(n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_,_,_), (_,_,_,_,_,_,_,_,ref i,_,_,_) => i }
|
|
|
|
(n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j,_,_), (_,_,_,_,_,_,_,_,_,ref j,_,_) => j }
|
|
|
|
(n10, n10_ref) -> K { (_,_,_,_,_,_,_,_,_,_,k,_), (_,_,_,_,_,_,_,_,_,_,ref k,_) => k }
|
|
|
|
(n11, n11_ref) -> L { (_,_,_,_,_,_,_,_,_,_,_,l), (_,_,_,_,_,_,_,_,_,_,_,ref l) => l }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-05-18 11:23:52 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use clone::Clone;
|
2013-05-19 03:51:14 -05:00
|
|
|
use cmp::*;
|
2013-05-18 11:23:52 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tuple_ref() {
|
|
|
|
let x = (~"foo", ~"bar");
|
|
|
|
assert_eq!(x.first_ref(), &~"foo");
|
|
|
|
assert_eq!(x.second_ref(), &~"bar");
|
|
|
|
}
|
2012-10-07 18:01:01 -05:00
|
|
|
|
2013-05-18 11:23:52 -05:00
|
|
|
#[test]
|
|
|
|
fn test_tuple() {
|
|
|
|
assert_eq!((948, 4039.48).first(), 948);
|
|
|
|
assert_eq!((34.5, ~"foo").second(), ~"foo");
|
|
|
|
assert_eq!(('a', 2).swap(), (2, 'a'));
|
|
|
|
}
|
2012-01-17 12:14:05 -06:00
|
|
|
|
2013-05-18 11:23:52 -05:00
|
|
|
#[test]
|
|
|
|
fn test_clone() {
|
|
|
|
let a = (1, ~"2");
|
|
|
|
let b = a.clone();
|
|
|
|
assert_eq!(a.first(), b.first());
|
|
|
|
assert_eq!(a.second(), b.second());
|
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|
2013-05-18 11:23:52 -05:00
|
|
|
#[test]
|
|
|
|
fn test_n_tuple() {
|
|
|
|
let t = (0u8, 1u16, 2u32, 3u64, 4u, 5i8, 6i16, 7i32, 8i64, 9i, 10f32, 11f64);
|
|
|
|
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);
|
|
|
|
|
|
|
|
assert_eq!(t.n0_ref(), &0u8);
|
|
|
|
assert_eq!(t.n1_ref(), &1u16);
|
|
|
|
assert_eq!(t.n2_ref(), &2u32);
|
|
|
|
assert_eq!(t.n3_ref(), &3u64);
|
|
|
|
assert_eq!(t.n4_ref(), &4u);
|
|
|
|
assert_eq!(t.n5_ref(), &5i8);
|
|
|
|
assert_eq!(t.n6_ref(), &6i16);
|
|
|
|
assert_eq!(t.n7_ref(), &7i32);
|
|
|
|
assert_eq!(t.n8_ref(), &8i64);
|
|
|
|
assert_eq!(t.n9_ref(), &9i);
|
|
|
|
assert_eq!(t.n10_ref(), &10f32);
|
|
|
|
assert_eq!(t.n11_ref(), &11f64);
|
|
|
|
}
|
2013-05-19 03:51:14 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tuple_cmp() {
|
2013-06-04 23:43:41 -05:00
|
|
|
let (small, big) = ((1u, 2u, 3u), (3u, 2u, 1u));
|
2013-05-19 03:51:14 -05:00
|
|
|
|
2013-08-08 15:07:22 -05:00
|
|
|
let nan = 0.0/0.0;
|
|
|
|
|
2013-05-19 03:51:14 -05:00
|
|
|
// Eq
|
|
|
|
assert_eq!(small, small);
|
|
|
|
assert_eq!(big, big);
|
|
|
|
assert!(small != big);
|
|
|
|
assert!(big != small);
|
|
|
|
|
|
|
|
// Ord
|
|
|
|
assert!(small < big);
|
|
|
|
assert!(!(small < small));
|
|
|
|
assert!(!(big < small));
|
|
|
|
assert!(!(big < big));
|
|
|
|
|
|
|
|
assert!(small <= small);
|
|
|
|
assert!(big <= big);
|
|
|
|
|
|
|
|
assert!(big > small);
|
|
|
|
assert!(small >= small);
|
|
|
|
assert!(big >= small);
|
|
|
|
assert!(big >= big);
|
|
|
|
|
2013-08-08 15:07:22 -05:00
|
|
|
assert!(!((1.0, 2.0) < (nan, 3.0)));
|
|
|
|
assert!(!((1.0, 2.0) <= (nan, 3.0)));
|
|
|
|
assert!(!((1.0, 2.0) > (nan, 3.0)));
|
|
|
|
assert!(!((1.0, 2.0) >= (nan, 3.0)));
|
|
|
|
assert!(((1.0, 2.0) < (2.0, nan)));
|
|
|
|
assert!(!((2.0, 2.0) < (2.0, nan)));
|
|
|
|
|
2013-05-19 03:51:14 -05:00
|
|
|
// TotalEq
|
|
|
|
assert!(small.equals(&small));
|
|
|
|
assert!(big.equals(&big));
|
|
|
|
assert!(!small.equals(&big));
|
|
|
|
assert!(!big.equals(&small));
|
|
|
|
|
|
|
|
// TotalOrd
|
|
|
|
assert_eq!(small.cmp(&small), Equal);
|
|
|
|
assert_eq!(big.cmp(&big), Equal);
|
|
|
|
assert_eq!(small.cmp(&big), Less);
|
|
|
|
assert_eq!(big.cmp(&small), Greater);
|
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
}
|